Hi all,
I'm performing a mediation analysis on regression discontinuity results, and have encountered the need to write my own program for the first time. The program below should store the indirect effect (a*b) of variable tlf_`x'_t1 on ach_resid_t1 so that I can bootstrap the coefficients and recover standard errors and confidence intervals. The issue I am having is that I want to run the program and bootstrap the results for each of 9 tlf variables separately. I've tried to do this using a forvalues loop, but stata "breaks" the loop when it encounters the end command. Any ideas on how I can get around this, so that I don't have to define the program and bootstrap for each component separately?
forvalues x=1/9 {
program define indirect_eff_tlf`x', rclass
reg tlf`x'_t1 me_in cenrating me_rating_int math i.year i.grade $tchr_cov, cluster(id)
gen a = _b[me_in]
reg ach_resid_t1 tlf`x'_t1 me_in cenrating me_rating_int math i.year i.grade $tchr_cov, cluster(id)
gen b = _b[tlf`x'_t1]
gen indir_eff_tlf`x' = a*b
sum indir_eff_tlf`x'
return scalar ie_tlf`x' = r(mean)
drop a b indir_eff_tlf`x'
end
bootstrap ie_tlf`x'=r(ie_tlf`x'), seed(12345) reps(50): indirect_eff_tlf`x'
}
Thanks so much for your thoughts!
Best,
Mindy
I'm performing a mediation analysis on regression discontinuity results, and have encountered the need to write my own program for the first time. The program below should store the indirect effect (a*b) of variable tlf_`x'_t1 on ach_resid_t1 so that I can bootstrap the coefficients and recover standard errors and confidence intervals. The issue I am having is that I want to run the program and bootstrap the results for each of 9 tlf variables separately. I've tried to do this using a forvalues loop, but stata "breaks" the loop when it encounters the end command. Any ideas on how I can get around this, so that I don't have to define the program and bootstrap for each component separately?
forvalues x=1/9 {
program define indirect_eff_tlf`x', rclass
reg tlf`x'_t1 me_in cenrating me_rating_int math i.year i.grade $tchr_cov, cluster(id)
gen a = _b[me_in]
reg ach_resid_t1 tlf`x'_t1 me_in cenrating me_rating_int math i.year i.grade $tchr_cov, cluster(id)
gen b = _b[tlf`x'_t1]
gen indir_eff_tlf`x' = a*b
sum indir_eff_tlf`x'
return scalar ie_tlf`x' = r(mean)
drop a b indir_eff_tlf`x'
end
bootstrap ie_tlf`x'=r(ie_tlf`x'), seed(12345) reps(50): indirect_eff_tlf`x'
}
Thanks so much for your thoughts!
Best,
Mindy
Comment