Dear Community,
I need to bootstrap a set of commands. Namely,
1. Run a regression
2. Obtain fitted values
3. Obtain mean from fitted values
I am doing thi in the context of medical cost estimation. Unfortunately, my code does not work:
Running the simulate command returns only empty values. I am guessing that somewhere in Step 3 (my program), the storing of the mean from my fitted values does not work.
Code:
Thank you!
I need to bootstrap a set of commands. Namely,
1. Run a regression
2. Obtain fitted values
3. Obtain mean from fitted values
I am doing thi in the context of medical cost estimation. Unfortunately, my code does not work:
Running the simulate command returns only empty values. I am guessing that somewhere in Step 3 (my program), the storing of the mean from my fitted values does not work.
Code:
Code:
* Step 1
quietly glm cost time if death==1, link(log) family(gamma)
predict GLM2
sum GLM2
return list
matrix GLMmean = (r(mean))
matrix list GLMmean
* Step 2: program
capture program drop GLMboot
program define GLMboot, rclass
preserve
bsample
glm cost time if death==1, link(log) family(gamma)
predict GLMbootfit2
sum GLMbootfit2
return scalar GLMmean_1 = r(mean)
restore
end
* Step 3: Monte Carlo
preserve
simulate GLMmean_1=r(mean), reps(10) seed(12345): GLMboot, rclass
bstat, n(2000)
estat bootstrap, all

Comment