one question I had: when applying bootstrap to xtreg, do you need some options to differentiate that the same panel being sampled and should be treated as different panels in bootstrap?
I think that's correct, if you want to treat X as fixed, you have to bootstrap the residuals. Basically in you data, you have residual and predicted Y (or if you want, the X variables), and then bootstrap the data, construct new y using the residual plus the predicted Y (or if using X, compute X'beta). This is the same as regular bootstrap, the only difference is you need to construct the dependent variable, not bootstrap the dependent variable.
it looks like the bootstrap sample is not correct.
you have panel data, so you cannot sample the observation directly, instead sample by panel, can you try if this work:
cap prog drop bootsXtregF
prog def bootsXtregF, rclass
preserve
bsample, cluster(id) id(newid)
tsset newid year
gen new_lev = xb+ehat
xtabond2 ??????? * your xtabond2 command here
return sca F=e(F)
restore
end
reg y x
predict xb
mat F=e(F)
predict r, r
tempfile f1
save `f1'
use `f1'
cap prog drop bootsRegF
prog def bootsRegF, rclass
preserve
bsample
gen new_y = xb+r
* if treating x as fixed
reg new_y x
*reg y x
return sca F = e(F)
restore
end
local iter = 20
mat R = J(`iter',4,.)
qui forv i=1/`iter' {
if `i' == 1 {
noi _dots 0
}
noi _dots `i' 0
drop _all
use `f1'
set seed `i'
simulate F=r(F), reps(20) : bootsRegF
bstat, stat(F)
mat b=e(b)
mat b_bs=e(b_bs)
mat se = e(se)
mat R[`i',1] = `i'
mat R[`i',2] = b[1,1]
mat R[`i',3] = b_bs[1,1]
mat R[`i',4] = se[1,1]
}
drop _all
svmat R
rename R1 seed
rename R2 est
rename R3 bs_est
rename R4 bs_se