Hi all
I want to create a variable containing the lower confidence interval and another with the upper confidence interval at 90% level from regression estimated in a loop.
gen coef = .
gen ci_lower = .
gen ci_upper = .
forv k = 1/10 {
capture drop keep
g keep = 0
replace keep = 1 if cycle==`k'
xi: ivreg2 dep indep i.day_of_week*i.week if keep, robust bw(auto) small
qui replace coef = _b[indep] if cycle==`k'
* Calculate confidence intervals (90%)
scalar z = invnormal(1 - (0.1 / 2))
scalar ci_lower_val = _b[indep] - z * _se[indep]
scalar ci_upper_val = _b[indep] + z * _se[indep]
* Store confidence intervals
replace ci_lower = ci_lower_val if cycle == `k'
replace ci_upper = ci_upper_val if cycle == `k'
}
This was a questions that came from a previous post and as it is unrelated to the main objective of the former post. I make it as a new post here. Thanks.
I want to create a variable containing the lower confidence interval and another with the upper confidence interval at 90% level from regression estimated in a loop.
gen coef = .
gen ci_lower = .
gen ci_upper = .
forv k = 1/10 {
capture drop keep
g keep = 0
replace keep = 1 if cycle==`k'
xi: ivreg2 dep indep i.day_of_week*i.week if keep, robust bw(auto) small
qui replace coef = _b[indep] if cycle==`k'
* Calculate confidence intervals (90%)
scalar z = invnormal(1 - (0.1 / 2))
scalar ci_lower_val = _b[indep] - z * _se[indep]
scalar ci_upper_val = _b[indep] + z * _se[indep]
* Store confidence intervals
replace ci_lower = ci_lower_val if cycle == `k'
replace ci_upper = ci_upper_val if cycle == `k'
}
This was a questions that came from a previous post and as it is unrelated to the main objective of the former post. I make it as a new post here. Thanks.
Comment