HI Statalist,
What do you use to create balance tables across treatment/control? Do you calculate them by hand, or do you have a preferred command? I've been using a combination of file write report and ttests (see code below), but I'm wondering if there's a more efficient way of doing this. Also, what about joint hypothesis tests, or tests of joint significance? The code below will only work for tests on individual variables.
Thanks,
Lucia
What do you use to create balance tables across treatment/control? Do you calculate them by hand, or do you have a preferred command? I've been using a combination of file write report and ttests (see code below), but I'm wondering if there's a more efficient way of doing this. Also, what about joint hypothesis tests, or tests of joint significance? The code below will only work for tests on individual variables.
Thanks,
Lucia
Code:
file open report using "balance.csv", write replace
file write report "Percent of Respondents Selecting Each Answer by T/C" _n
file write report ",Treatment,Control,Difference in Means" _n
loc vars ///list variables to test here
foreach var of loc vars {
loc lbl: var label `var'
loc lbl = subinstr("`lbl'", ",","",.)
file write report "`lbl'"
qui ttest `var', by(treatment)
if `r(p)' > 0.10 {
loc p ""
}
else if `r(p)' <= 0.10 & `r(p)' > 0.05 {
loc p "*"
}
else if `r(p)' <= 0.05 & `r(p)' > 0.01 {
loc p "**"
}
else if `r(p)' <= 0.01 {
loc p "***"
}
loc mean`var' = round(`r(mu_2)'-`r(mu_1)', 0.002)
file write report ",`=round(`r(mu_2)', 0.002)', `=round(`r(mu_1)', 0.002)', `mean`var''" _n
di "`var' printed"
}
distinct surveyid if treatment == 1
file write report "N, `r(ndistinct)'"
distinct surveyid if treatment == 0
file write report ",`r(ndistinct)'"
file close report
