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: bootstrap weighted mean


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: bootstrap weighted mean
Date   Wed, 2 Oct 2013 09:27:11 +0100

The third argument you pass to -myratio- is in practice

weight,

with comma included

which may well be causing the syntax error. Positional arguments `1'
`2' etc. are identified by Stata using two rules, spaces separate, but
double quotation marks unite. A minimal test of this is to type

weight ,

It probably doesn't matter, but it's better style to use scalars
rather than locals to handle results like yours. Also, it's better
style to pass weights to programs as such, not as extra variables, as
Joseph shows. That's more flexible too.

Nick
[email protected]


On 2 October 2013 03:40, Shuaizhang Feng <[email protected]> wrote:
> Dear list:
>
> I was trying to bootstrap standard errors for the mean of two
> variables. When I do so for simple means, i use the following ado
> file.
>
> program myratio, rclass
>          summarize `1'
>           local a1 = r(mean)
>           summarize `2'
>           local a2 = r(mean)
>  return scalar ratio = `a1'/`a2'
> end
>
> and then do the following:
>
> .bootstrap r(ratio), reps(100) saving(cratio, replace): myratio u1 u2, detail
>
> and this gives the results as expected.
>
> however, when i wanted to do ratio of weighted means, i modified the
> ado file as follows:
>
> program myratio_w, rclass
>       summarize `1'[iw=`3']
>           local a1 = r(mean)
>       summarize `2'[iw=`3']
>           local a2 = r(mean)
>  return scalar ratio = `a1'/`a2'
> end
>
>
> and then use:
>
> bootstrap r(ratio), reps(100) saving(cratio, replace): myratio_w u1 u2
> weight, detail
>
> then stata does not work properly and gives me the following message:
>
> invalid syntax
> an error occurred when bootstrap executed myratio_w
> r(198);
>
>
> I am wondering if anyone from the list can help me out. the difference
> between the two ado files seem small Thanks in advance.
>
> SZ
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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