Hi everyone,
I've been attempting to run a two-step bootstrap (for background see http://www.statalist.org/forums/foru...age-estimation) but keep encountering an invalid syntax (r(198)) error in the simulate stage. Have tried numerous ways to resolve the issue but to no avail, and was wondering if anyone could point me in the right direction.
This is the code I'm running:
Would be very grateful for any help!
I've been attempting to run a two-step bootstrap (for background see http://www.statalist.org/forums/foru...age-estimation) but keep encountering an invalid syntax (r(198)) error in the simulate stage. Have tried numerous ways to resolve the issue but to no avail, and was wondering if anyone could point me in the right direction.
This is the code I'm running:
Code:
cd "(my file location)"
set trace on
set traced 1
ma drop _all
scalar drop _all
* write program
capture program drop prog_boot
program prog_boot, eclass
syntax varlist [if]
use file1, clear
preserve
foreach m in 0 1 {
foreach p in 1101 1401 1402 1404 1414 1423 2101 2102 2107 2112 2114 3201 3202 3203 ///
3204 3206 3209 3213 3233 3401 3402 3403 3404 3416 3432 4101 4102 4104 4105 4107 ///
4201 4206 4210 4222 4231 4232 4401 4406 4408 4412 4413 4415 4433 4452 5001 5101 ///
5105 5108 5113 5114 5301 5303 5305 5325 5327 5329 5332 6201 6223 6227 {
bsample if male==`m' & wave==`1995' & county==`p' & inreg==1 //get bootstrap sample
reg var1 var2 var3 var4 var5 var6 ///
if male==`m' & wave==`1995' & county==`p' //perform regression
scalar var1995`p'`m'=_b[var2]
scalar int1995`p'`m'=_b[_cons]
}
}
restore
use file1, clear
marksample touse // mark relevant sample
preserve
bsample 100 if `touse' //generate bootstrap sample for second stage
foreach p in 1101 1401 1402 1404 1414 1423 2101 2102 2107 2112 2114 3201 3202 3203 ///
3204 3206 3209 3213 3233 3401 3402 3403 3404 3416 3432 4101 4102 4104 4105 4107 ///
4201 4206 4210 4222 4231 4232 4401 4406 4408 4412 4413 4415 4433 4452 5001 5101 ///
5105 5108 5113 5114 5301 5303 5305 5325 5327 5329 5332 6201 6223 6227 {
foreach m in 0 1 {
replace var=var1995`p'`m' if county==`p' & male==`m' & wave==1995
replace int=int1995`p'`m' if county==`p' & male==`m' & wave==1995
}
}
regress `varlist' i.yob //do second stage regression
restore
end
* run regression
use file2, clear
qui reg var2 var int var7 var8 var9 var10 var11 i.yob if wave==1995 & edreg==1 //run actual regression
scalar nobs = e(N) //save no. of observations
scalar rsqd = e(r2) //save R^2
matrix coef = e(b) //save coeff matrix
* bootstrap
simulate _b, reps(50): prog_boot var2 var int var7 var8 var9 var10 var11 if edreg==1 & wave==1995
bstat, stat(coef)

Comment