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
Thu, 10 Mar 2011 13:13:17 +1100
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]
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: Thursday, 10 March 2011 6:01 AM
To: [email protected]
Subject: Re: st: svy bootstrap
Nick Cox and Michael Palmer have been discussing how to write a program that conforms to the expectation of -bs4rw-.
One sentence summary of Nick's suggestions: you only need one -syntax-, and based on what you are sending within the call to -bootstrap-, the necessary syntax is
syntax [pweight /]
that would work pretty much as
local weight pweight
local exp <the name of the weight variable>
so later in the program you will use them as
logit ... [`weight' = `exp']
regress ... [`weight' = `exp']
mean ... [`weight' = `exp']
Do not break this down into two separate programs -- that's just complicating things, as you need to pass the weights and parse inputs in each of these programs. (Generally, small programs that do only one thing are better, but -logit- and -regress- are already such programs, and you lose the temporary vars that you -predict-ed when you exit your -model1- and -model2- programs).
On Wed, Mar 9, 2011 at 4:09 AM, Nick Cox <[email protected]> wrote:
> That looks like a clue to me.
>
> -syntax- is seeing nothing that it recognises as a varlist.
>
> More seriously, you are dropping a -program- called -model1- but then
> not redefining it. -syntax- looks for a macro named 0, and if it can't
> find one it tries to parse an empty string. An empty string can't
> include a varlist.
>
> You do the right thing by -program twopart- which defines a program.
> You also need -program define model1- and the same for -model2-. (The
> "define"s are optional since Stata 8; I include them here to stress
> what -program- does in that case.)
>
> When you run a -program- local macro 0 is created for you as the
> program arguments. But if you run -syntax- by itself, which is
> perfectly legal, it does need a macro 0 to exist.
>
> Nick
>
> On Wed, Mar 9, 2011 at 8:01 AM, Michael Palmer
> <[email protected]> wrote:
>> 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
>>
> *
> * 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/