Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Mark McGovern <markemcgovern@GMAIL.COM> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Program syntax for svy bootstrap or bs4rw |

Date |
Mon, 25 Jun 2012 18:45:21 -0400 |

Thank you Steve and Stas for your suggestions. For now I can work with bs4rw, although at some point I think I might need to use some of the functionality of svy, so I may have to return to this in the future. As you pointed out Steve, from the Stata 12 programming manual (p.326): 1. Command must be eclass and allow iweights and accept the standard estimation syntax. 2. Command must save the model coefficients and ancillary parameters in e(b) and the estimation sample size in e(N), and it must identify the estimation subsample in e(sample); 3. svy’s vce(bootstrap), vce(brr), and vce(sdr) require that command have svyb as a property. I thought these were satisfied as the original code below does return results in e() in the usual way from "regress". For example, specifically overwriting e() does not help as in the below. Regards, Mark webuse nmihs_bs, clear svyset _n [pweight=finwgt], bsrweight(bsrw1-bsrw5) vce(bootstrap) singleunit(missing) capture program drop test1 program define test1, eclass properties(svyb) syntax [if] [in] [pw iw] marksample touse tempvar b V qui xi:reg age race [`weight'`exp'] if `touse' capture drop re1 predict re1 qui xi:reg birthwgt re1 [`weight'`exp'] if `touse' local nobs = e(N) matrix `b' = e(b) matrix `V' = e(V) ereturn post `b' `V', esample(`touse') ereturn local cmd="test1" ereturn scalar N = `nobs' ereturn display end svy : test1 On Sat, Jun 23, 2012 at 2:07 PM, Stas Kolenikov <skolenik@gmail.com> wrote: > As a short cut, you can try to omit -eclass-, so that your program > leaves the last estimates in the memory, treat the weights as [iw], > and run -bs4rw _b- to produce the standard errors. > > On Sat, Jun 23, 2012 at 12:26 PM, Steve Samuels <sjsamuels@gmail.com> wrote: >> Sorry for the double post. I had two drafts of the original message and forgotten that I had sent one. >> >> S. >> >> The Programming manual entry "Writing programs for use with svy" says that to use a command with a svy prefix it must return e(b), e(N), and e(sample). Even though you use none of these, perhaps their absence is causing the error. >> >> >> Steve >> sjsamuels@gmail.com >> >> On Jun 22, 2012, at 8:09 PM, Mark McGovern wrote: >> >> Thank you very much for the suggestion, I will look again at cmp. The >> point of this is to use interviewer effects for selection. There are >> some alternative approaches, however they all involve a similar two >> step procedure which would require a similar bootstrap for the >> standard errors. I have added weights to the program commands, however >> I must still be omitting something else. Error: "last estimates not >> found" Any further thoughts would be appreciated. >> >> webuse nmihs_bs >> svyset _n [pweight=finwgt], bsrweight(bsrw1-bsrw5) vce(bootstrap) >> singleunit(missing) >> >> program define test1, eclass properties(svyb) >> syntax [if] [pw iw] [, NULLOPT] >> xi:reg age race [`weight'`exp'] >> capture drop re1 >> predict re1 >> xi:reg birthwgt re1 [`weight'`exp'] >> ereturn local cmd="test1" >> end >> >> svy : test1 >> >> Regards, >> >> Mark >> >> On Fri, Jun 22, 2012 at 3:35 PM, Stas Kolenikov <skolenik@gmail.com> wrote: >>> Your program does not use the weights anywhere. It accepts them, as >>> the -svy- requirements specify, but it just absorbs them without >>> passing them on to the estimation commands. So it does run the same >>> commands on the same data set, even though -svy bootstrap- does the >>> best job it can in giving the right weights to you. >>> >>> In general, I would find it questionable that you make point >>> predictions of the random effects and use them in any serious way >>> later. The random effects must be integrated over, and you need to >>> find a way to do that within your convoluted version of the Heckman >>> model. May be you can cast this as a -cmp- model -- check David >>> Roodman's work on that. >>> >>> On Fri, Jun 22, 2012 at 11:59 AM, Mark McGovern <markemcgovern@gmail.com> wrote: >>>> Dear all, >>>> >>>> I am attempting to write a simple program for a bootstrap in which >>>> predicted values (random effects) are estimated in a first stage and >>>> then used in a heckman selection model in the second. >>>> >>>> This works fine when I use the standard bootstrap command, however I >>>> am using survey data and would like to account for this with SVY as >>>> discussed on this list previously. >>>> >>>> I have tried to meet the syntax requirements for SVY as outlined in >>>> the programming manual, and have tried various additions but I am >>>> having trouble with the program. I noted the discussion on >>>> http://www.stata.com/statalist/archive/2011-03/msg01442.html and also >>>> tried the bs4rw command. I would appreciate your advice. I am using >>>> Stata 12 MP. >>>> >>>> Here is a simple illustration with the NHIMES data. I find that the >>>> same sample is used in each bootstrap. >>>> >>>> I svyset the data and run the command (with just 5 replications for testing). >>>> >>>> webuse nmihs_bs >>>> svyset _n [pweight=finwgt], bsrweight(bsrw1-bsrw5) vce(bootstrap) >>>> singleunit(missing) >>>> >>>> program define test1, eclass properties(svyb) >>>> syntax [if] [pw iw] [, NULLOPT] >>>> xi:reg age race >>>> capture drop re1 >>>> predict re1 >>>> xi:reg birthwgt re1 >>>> ereturn local cmd="test1" >>>> end >>>> >>>> svy : test1 >>>> >>>> bs4rw , rw(bsrw1-bsrw5) noisily: test1 [pweight=finwgt] >>>> >>>> Regards, >>>> >>>> Mark >>>> * >>>> * For searches and help try: >>>> * http://www.stata.com/help.cgi?search >>>> * http://www.stata.com/support/statalist/faq >>>> * http://www.ats.ucla.edu/stat/stata/ >>> >>> >>> >>> -- >>> ---- Stas Kolenikov >>> -- http://stas.kolenikov.name >>> ---- Senior Survey Statistician, Abt SRBI >>> -- Opinions stated in this email are mine only, and do not reflect the >>> position of my employer >>> >>> * >>> * For searches and help try: >>> * http://www.stata.com/help.cgi?search >>> * http://www.stata.com/support/statalist/faq >>> * http://www.ats.ucla.edu/stat/stata/ >> >> * >> * For searches and help try: >> * http://www.stata.com/help.cgi?search >> * http://www.stata.com/support/statalist/faq >> * http://www.ats.ucla.edu/stat/stata/ >> >> >> * >> * For searches and help try: >> * http://www.stata.com/help.cgi?search >> * http://www.stata.com/support/statalist/faq >> * http://www.ats.ucla.edu/stat/stata/ > > > > -- > ---- Stas Kolenikov > -- http://stas.kolenikov.name > ---- Senior Survey Statistician, Abt SRBI > -- Opinions stated in this email are mine only, and do not reflect the > position of my employer > > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/statalist/faq > * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**Re: st: Program syntax for svy bootstrap or bs4rw***From:*Stas Kolenikov <skolenik@gmail.com>

**References**:**st: Program syntax for svy bootstrap or bs4rw***From:*Mark McGovern <markemcgovern@gmail.com>

**Re: st: Program syntax for svy bootstrap or bs4rw***From:*Stas Kolenikov <skolenik@gmail.com>

**Re: st: Program syntax for svy bootstrap or bs4rw***From:*Mark McGovern <markemcgovern@gmail.com>

**Re: st: Program syntax for svy bootstrap or bs4rw***From:*Steve Samuels <sjsamuels@gmail.com>

**Re: st: Program syntax for svy bootstrap or bs4rw***From:*Stas Kolenikov <skolenik@gmail.com>

- Prev by Date:
**st: esttab and p-values question** - Next by Date:
**st: -esttab- after margins** - Previous by thread:
**Re: st: Program syntax for svy bootstrap or bs4rw** - Next by thread:
**Re: st: Program syntax for svy bootstrap or bs4rw** - Index(es):