Dear list,
I am using a very specific method with no ready-made Stata command to calculate a quantity of interest, and I was asked to provide bootstrap confidence interval for the quantity. I learnt that the bootstrap command in Stata can be combined with user-written program. However, I have difficulties using this function properly.
Below is an example:
As you can see, it does not work. What I really want to do is as follows, where I no longer use the bootstrap command but instead use bsample:
I want to combine bootstrap with my own program instead of creating a lot of samples using bsample, as bootstrap also provides other useful functions (e.g., calculating different types of standard errors).
Thank you!
I am using a very specific method with no ready-made Stata command to calculate a quantity of interest, and I was asked to provide bootstrap confidence interval for the quantity. I learnt that the bootstrap command in Stata can be combined with user-written program. However, I have difficulties using this function properly.
Below is an example:
Code:
capture drop _all sysuse auto, clear program drop _all program myboot ,rclass replace price = price*2 keep in 1 /* my calculation eventually produces a data set with one observation and a few variables containing the values produced from my calculation (e.g., a latent measure of average level of happiness among British men as calculated using a complex method). I need to calculate the bootstrap CI of the values as recorded in these variables. */ sum price, meanonly return scalar outcome=r(mean) end bootstrap outcome=r(outcome), reps(100): myboot
Code:
sysuse auto, clear set seed 1 foreach boot of numlist 1(1)100 { preserve bsample replace price = price*2 keep in 1 gen outcome=price gen boot=`boot' tempfile b`boot' save `b`boot'' restore } use `b1', clear forvalues p=2/100 { append using `b`p'' } centile outcome, centile(2.5 50 97.5)
Thank you!
Comment