Bookmark and Share

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]

RE: st: svy bootstrap


From   "Michael Palmer" <[email protected]>
To   <[email protected]>
Subject   RE: st: svy bootstrap
Date   Wed, 9 Mar 2011 19:01:44 +1100

Many thanks, I have written two separate programs for each syntax to run within the main program. 
Stata stops at the `syntax varlist [pweight]' line with the error message 'varlist required'. 
Any clues? Tomorrow is another day, hopefully I'll figure it out.  

svyset [pweight=psindwt], strata(domain) psu(commcode)
set trace on
set more off

capture program drop model1
tempvar pr_y
syntax varlist [pweight] 
quietly logit `varlist' `weight' 
quietly predict `pr_y', pr
end

capture program drop model2 
tempar yhat ehat
syntax varlist [pweight]
quietly regress `varlist' `weight'
quietly predict `yhat', xb
quietly predict `ehat', res
end

capture program drop twopart
program twopart, rclass
tempname sm1 sm0 m_1 m_2 m_3 m_4 
tempvar pr_y yhat ehat smear smear_ins sm1 smear_noins sm2 yhat_duan yhat_pwd1 yhat_pwd0 y_pwd1 y_pwd0 
do model1.do
model1 inpat_public $xlist1 if age > 5 
do model2.do
model2 ipexp_public_log $xlist1 if age > 5 & inpat_public==1 
 


Michael Palmer
PhD Candidate 
National Centre for Epidemiology and Population Health 
The Australian National University 
Ph. 6125 0538
M. 0437 867 940

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: Tuesday, 8 March 2011 8:13 PM
To: [email protected]
Subject: Re: st: svy bootstrap

It's rare to need two -syntax- statements. I haven't tried to understand this, but my guess is that the second -syntax- statement is messing up the results of the first.

In general, treating a program as a black box is doomed to failure.
You need to -set trace on- and see where the error is generated.

Nick

On Tue, Mar 8, 2011 at 7:05 AM, Michael Palmer <[email protected]> wrote:
> I don't know how to do this. I have spent the day reading Stata manuals and various other references.
> Obviously the below do file is wrong (error message 'invalid syntax'). I gather that I must write a separate program for the weights and then incorporate it in the below twopart program. I am at a loss, any help would be greatly appreciated.
>
>
> capture program drop twopart
> program twopart, rclass
> tempname sm1 sm0 m_1 m_2 m_3 m_4
> tempvar pr_y yhat ehat smear smear_ins sm1 smear_noins sm2 yhat_duan 
> yhat_pwd1 yhat_pwd0 y_pwd1 y_pwd0 syntax varlist [pweight] [=exp] [if] 
> syntax newvarlist [pweight] [=exp] [if] logit inpat_public $xlist1 if 
> age > 5 `weight' `if' `exp'
> predict `pr_y', pr
> reg ipexp_public_log $xlist1 if age > 5 & inpat_public==1 `weight' `if' `exp'
> predict `yhat', xb
> predict `ehat', residuals
>
> egen `smear_ins' = mean(exp(`ehat')) if insurance==1 summ `smear_ins' 
> `typlist' `if' `exp'
> scalar `sm1' = r(max)
> egen `smear_noins' = mean(exp(`ehat')) if insurance==0 summ 
> `smear_noins' `typlist' `if' `exp'
> scalar `sm0' = r(max)
> gen `yhat_duan' = exp(`yhat')*`sm1' if insurance==1 replace 
> `yhat_duan' = exp(`yhat')*`sm0' if insurance==0
>
> gen `yhat_pwd1' = `yhat_duan' if pwd==1 mean `yhat_pwd1' `typlist' 
> `if' `exp'
> scalar `m_1' = _b[`yhat_pwd1']
> gen `yhat_pwd0' = `yhat_duan' if pwd==0 mean `yhat_pwd0' `typlist' 
> `if' `exp'
> scalar `m_2' = _b[`yhat_pwd0']
> gen `y_pwd1' = `pr_y' if pwd==1
> mean `y_pwd1' `typlist' `if' `exp'
> scalar `m_3' = _b[`y_pwd1']
> gen `y_pwd0' = `pr_y' if pwd==0
> mean `y_pwd0' `typlist' `if' `exp'
> scalar `m_4' = _b[`y_pwd0']
>
> return scalar prod2 = `m_1'*`m_3' - `m_2'*`m_4'
> end
>
> set more off
> twopart
> return list
> bsweights bsw, reps(100) n(-1)
> bs4rw (prod2=r(prod2)), rw(bsw*): twopart [pw=psindwt]
>
> Best regards,
>
>
> Michael Palmer
> PhD Candidate
> National Centre for Epidemiology and Population Health The Australian 
> National University Ph. 6125 0538 M. 0437 867 940
>
> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf Of Stas 
> Kolenikov
> Sent: Monday, 7 March 2011 11:26 PM
> To: [email protected]
> Subject: Re: st: svy bootstrap
>
> Take a look at the [R] bootstrap entry and their running examples.
> Yours will run along the similar lines, and have [pw] where applicable. Remember, unlike the -bootstrap- that actually changes the data in memory, the survey bootstrap only substitutes different sets of weight variables.
>
> On Mon, Mar 7, 2011 at 2:24 AM, Michael Palmer <[email protected]> wrote:
>> Thank you for your response. Your explanation makes sense and I'll be sure to cite your paper. But I'm not exactly sure how I might rewrite the program so that it accepts pw. Do you happen to have any example programs that you could send me or better yet offer any advice on how to rewrite my program?
>>
>> Best regards,
>>
>> Michael Palmer
>> PhD Candidate
>> National Centre for Epidemiology and Population Health The Australian 
>> National University Ph. 6125 0538 M. 0437 867 940
>>
>> -----Original Message-----
>> From: [email protected]
>> [mailto:[email protected]] On Behalf Of Stas 
>> Kolenikov
>> Sent: Monday, 7 March 2011 3:24 PM
>> To: [email protected]
>> Subject: Re: st: svy bootstrap
>>
>> The command -mean- had difficulties understanding what the variable name was. It was expecting a variable name, but -r(prod2)- was not a variable. Of course it is not a factor variable or a time series lagged variable, but that's the best error message Stata could send to you, given that nobody would put anything but variable names after -mean-.
>>
>> To make your program work with -bs4rw- or -svy, vce(bootstrap)-, you 
>> need to rewrite it so that it accepts [pw] or [iw] and runs all 
>> estimation commands with those weights... and produces something 
>> reasonable in the end. Then you can run -bs4rw (prod2 = r(prod2) ), 
>> rw( bsw* ) : twopart [pw=original weight]- to obtain your bootstrap 
>> standard errors. (I would not trust 50 replicates that much, and it 
>> should be pretty easy to increase this number; it does not look like 
>> you have any extraordinary difficult computations within your
>> program.)
>>
>> I see that you found my -bsweights- command useful, and I hope you will cite my SJ paper documenting this command.
>>
>> On Sun, Mar 6, 2011 at 10:20 PM, Michael Palmer <[email protected]> wrote:
>>> Dear Statalist,
>>>
>>> I am trying to bootstrap standard errors in a two-part model using 
>>> complex survey data. The first model is a logit and the second a log 
>>> linear model of expenditures. From the below do file I get the 
>>> following error message. Any help is greatly appreciated.
>>>
>>>  bsweights bsw, reps(40) n(-1)
>>>  svyset [pweight=psindwt], strata(domain) psu(commcode)
>>> vce(bootstrap)
>>> bsrweight(bsw*)
>>> . svy: mean r(prod2)
>>> (running mean on estimation sample)
>>> factor variables and time-series operators not allowed an error 
>>> occurred when bootstrap executed mean r(101);
>>>
>>
>> --
>> Stas Kolenikov, also found at http://stas.kolenikov.name Small print:
>> I use this email account for mailing lists only.
>>
>> *
>> *   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, also found at http://stas.kolenikov.name Small print: I use this email account for mailing lists only.
>
> *
> *   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/



*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index