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   Stas Kolenikov <[email protected]>
To   [email protected]
Subject   Re: st: svy bootstrap
Date   Wed, 9 Mar 2011 14:00:40 -0500

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/


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