我需要帮助将自举系数及其上下 95% CI 粘贴到新变量中以生成图表。
我尝试了下面的代码。看起来标量已成功检索,但我无法在使用replace
.
clear all
forvalues j=0/1{
foreach l in P2 P3 P4 {
use `l'_per_`j', clear
set seed 1
reg estimate xaxis
predict yhat
gen yhat_bs=yhat
gen ll_95per=.
gen ul_95per=.
local N = _N
foreach i in 1/11 { //number of time periods to be predicted
bootstrap pred=(_b[_cons] + _b[xaxis]*`i'), reps(1000) seed(1): reg
estimate xaxis
matrix b=e(b)
scalar sb=b[1,1]
matrix ci_normal=e(ci_normal)
local par=b[1,1] //coefficient bootstrap
local ll=ci_normal[1,1] //lower CI 95%
local ul=ci_normal[2,1] //upper CI 95%
replace yhat_bs=`par' if xaxis==`i'
replace ll_95per=`ll' if xaxis==`i'
replace ul_95per=`ul' if xaxis==`i'
}
save `l'_per_`j'_lin_trend, replace
}
}