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   Sun, 13 Mar 2011 16:54:31 +1100

Thanks Nick, I wrote that segment so as I could use the [`weight'=`exp'] option on the mean command (for some reason it would not let me run the weights syntax on the summ command. I take your point. 

I corrected this segment and ran the do file again only to get the same error message. The error occurs when running the twopart program on estimation sample. 

It appears after the syntax line:

syntax [pweight /] [if]
"Options not allowed" 

Then down a bit further after some unintelligible code: 

"an error occurred when 'caller' executed 'cmdname'"
"an error occurred when bs4rw executed twopart"

I'm beginning to think I'm never going to get this thing to run. 

Cheers, Michael  

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: Friday, 11 March 2011 7:50 PM
To: [email protected]
Subject: Re: st: svy bootstrap

You used -set trace on- then. Which line of your program triggered the error?

Without trying to understand your code, I spotted this segment

summ `smear_noins'
gen `smear_noins1' = r(mean)
summ `smear_noins1'
scalar `sm0' = r(max)

Here you -summarize- one variable and put its mean into another variable. Then you -summarize- that new variable. But there's nothing in there that you need to -summarize-; by construction the variable is a constant. The new maximum is just the same as the old mean.
Did you mean to do precisely that? At worst there is a bug in there.

Earlier in the program there is a very similar block of code raising similar questions.

Nick

On Fri, Mar 11, 2011 at 7:49 AM, Michael Palmer <[email protected]> wrote:
> Thank you very much for your advice, I have tweaked the program according to your suggestions but am getting an error message after the syntax line ('options not allowed') and later: 'an error occurred when bs4rw executed twopart'. Any thoughts?
>
> The do file now reads:
>
> capture program drop twopart
> program twopart, rclass
> tempname sm1 sm0 smear prob m_1 m_2 m_3 m_4 i_1 i_2 i_3 i_4 b_1 b_2 
> c_1 c_2 d_1 d_2 tempvar pr_y yhat ehat smear smear_ins smear_ins1 sm1 
> smear_noins smear_noins1 sm2 yhat_duan yhat_pwd1 yhat_pwd0 y_pwd1 
> y_pwd0 syntax [pweight /] [if] marksample touse logit inpat_public 
> $xlist1 [`weight'=`exp'] if age > 5 & `touse'
> predict `pr_y', pr
> reg ipexp_public_log $xlist1 [`weight'=`exp'] if age > 5 & inpat_public==1 & `touse'
> predict `yhat', xb
> predict `ehat', residuals
>
> gen `smear_ins' = exp(`ehat') if insurance==1 mean `smear_ins' 
> [`weight'=`exp'] summ `smear_ins'
> gen `smear_ins1' = r(mean)
> summ `smear_ins1'
> scalar `sm1' = r(max)
> gen `smear_noins' = exp(`ehat') if insurance==0 mean `smear_noins' 
> [`weight'=`exp'] summ `smear_noins'
> gen `smear_noins1' = r(mean)
> summ `smear_noins1'
> scalar `sm0' = r(max)
> gen `yhat_duan' = exp(`yhat')*`sm1' if insurance==1 replace 
> `yhat_duan' = exp(`yhat')*`sm0' if insurance==0 mean `yhat_duan' 
> [`weight'=`exp'] scalar `smear' = _b[`yhat_duan'] mean `pr_y' 
> [`weight'=`exp'] scalar `prob' = _b[`pr_y']
>
> gen `yhat_pwd1' = `yhat_duan' if pwd==1 mean `yhat_pwd1' 
> [`weight'=`exp'] scalar `m_1' = _b[`yhat_pwd1'] gen `yhat_pwd0' = 
> `yhat_duan' if pwd==0 mean `yhat_pwd0' [`weight'=`exp'] scalar `m_2' = 
> _b[`yhat_pwd0'] gen `y_pwd1' = `pr_y' if pwd==1 mean `y_pwd1' 
> [`weight'=`exp'] scalar `m_3' = _b[`y_pwd1'] gen `y_pwd0' = `pr_y' if 
> pwd==0 mean `y_pwd0' [`weight'=`exp'] scalar `m_4' = _b[`y_pwd0']
>
> return scalar bpwd = `m_1'*`m_3' - `m_2'*`m_4'
>
> end
>
> set trace on
> set more off
> twopart [pweight=psindwt]
> return list
> bsweights bsw, reps(100) n(-1)
> bs4rw bpwd=r(bpwd), 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 Nick Cox
> Sent: Thursday, 10 March 2011 8:14 PM
> To: [email protected]
> Subject: Re: st: svy bootstrap
>
> As advised before, use -set trace- to see where the error occurs.
>
> Note that your invocations of  `if' will do nothing. You never define any local macro -if- either directly or indirectly through -syntax-.
>
> Similar comment for `typlist'. Empty because never defined.
>
> Your -summ- calls name `exp' but if you want these -summarize-s to use weights you need to use the [pw=exp] syntax just as in other commands.
>
> I didn't read to the end.
>
> Nick
>
> On Thu, Mar 10, 2011 at 2:13 AM, Michael Palmer <[email protected]> wrote:
>> Thanks so much for your reply. I went ahead with the suggested code in the single program.
>> However, I was met with the error message: '=unknown weight type'.
>>
>> The revised do file is:
>>
>> capture program drop twopart
>> program twopart, rclass
>> tempname sm1 sm0 smear prob 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 [pweight /] logit inpat_public $xlist1 if age > 
>> 5 [`weight'=`exp'] predict `pr_y', pr reg ipexp_public_log $xlist1 if 
>> age > 5 & inpat_public==1 [`weight'=`exp'] predict `yhat', xb predict 
>> `ehat', residuals
>>
>> egen `smear_ins' = mean(exp(`ehat')) if insurance==1  
>> [`weight'=`exp'] summ `smear_ins' `typlist' `if' `exp'
>> scalar `sm1' = r(max)
>> egen `smear_noins' = mean(exp(`ehat')) if insurance==0 
>> [`weight'=`exp'] 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 mean `yhat_duan'
>> scalar `smear' = _b[`yhat_duan']
>> mean `pr_y'
>> scalar `prob' = _b[`pr_y']
>>
>> gen `yhat_pwd1' = `yhat_duan' if pwd==1 mean `yhat_pwd1'
>> [`weight'=`exp'] scalar `m_1' = _b[`yhat_pwd1'] gen `yhat_pwd0' = 
>> `yhat_duan' if pwd==0 mean `yhat_pwd0' [`weight'=`exp'] scalar `m_2' 
>> = _b[`yhat_pwd0'] gen `y_pwd1' = `pr_y' if pwd==1 mean `y_pwd1'
>> [`weight'=`exp'] scalar `m_3' = _b[`y_pwd1'] gen `y_pwd0' = `pr_y' if 
>> pwd==0 mean `y_pwd0' [`weight'=`exp'] scalar `m_4' = _b[`y_pwd0']
>>
>> return scalar bpwd = `m_1'*`m_3' - `m_2'*`m_4'
>>
>> end
>>
>> set more off
>> twopart
>> return list
>> bsweights bsw, reps(100) n(-1)
>> bs4rw (bpwd=r(pwd)), rw(bsw*): twopart [pw=psindwt]

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