Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: bootstrap program problem


From   Fred Wolfe <[email protected]>
To   [email protected]
Subject   st: bootstrap program problem
Date   Thu, 27 Oct 2005 19:26:23 -0500

I have written a program to calculate differences between categories using bootstrap.

. ndbdifference sex ,by(ra) seed(1) reps(25)

Difference between ra categories Number of obs = 40931
Replications = 25

------------------------------------------------------------------------------
| Observed Bootstrap Normal-based
| Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
sex_b | -.0353085 .0045013 -7.84 0.000 -.0441309 -.0264861
------------------------------------------------------------------------------

The program works as directed.

The code is:


program define ndbdifference
version 9.0
syntax varlist [if] [in] ,by(varname) [seed(real -1) Reverse reps(real 100)]
marksample touse, novarlist
if "`seed'" != "-1" {
set seed `seed'
}
foreach var of varlist `varlist' {
preserve
qui keep if `touse'
keep `var' `by'
qui keep if !mi(`var',`by')
bootstrap `"`var'_b"'=r(dif), ///
reps(`reps') nowarn nodots nolegend title(Difference between `by' categories) ///
: difference `var',by(`by') `reverse'
restore
}

end

However, when I add -bca- to this line:
bca : difference `var',by(`by') `reverse'

The Stata program crashes with this error:

- if `"`bca'"' != "" {
= if `"bca"' != "" {
- forvalues i = 1/`K' {
= forvalues i = 1/1 {
- local name : word `i' of `names'
= local name : word 1 of sex_b
- local exp_list `exp_list' `name'=(`exp`i'')
= local exp_list `"sex_b"' =r(dif) sex_b=(r(dif))
invalid syntax

I don't understand this error, as I am not sure what is correct. However, if I charge the bootstrap line to:

bootstrap `var'_b=r(dif), ///

The program runs correctly until I add -bca- again.

This time it gives the following error:

= di as err "name sex_b already specified"
name sex_b already specified

in the section for bca.

I wonder if anyone can point me in the right direction toward understanding this error.

Thanks,

Fred

Fred Wolfe
National Data Bank for Rheumatic Diseases
Wichita, Kansas
Tel (316) 263-2125 Fax (316) 263-0761
[email protected]


*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index