Helo, I want to automate my balance table but I am encountering an issue.
Here, I would want the N to corresponds to the number of observation for each treatment group. However, it does not seem to be that way, it keeps giving me the total number of observation in each wave (Not in each wave and each treatment group).
Can you please help me identify how I can change this:
capt prog drop balancetable
program balancetable, eclass
syntax varlist if, by(varname)
marksample touse
markout `touse' `by'
tempname mu_1 mu_2 mu_3 mu_4 b_1 b_2 b_3 p_1 p_2 p_3 n1 n2 n3 n4
capture drop TD*
tab `by', gen(TD)
foreach var of local varlist {
* Full Sample
cap confirm variable `var'
if _rc == 0 {
*cap assert !missing(`var')
*if _rc == 0 {
reg `var' TD1 TD2 TD3 TD4 `if', nocons
matrix A=e(b)
mat `mu_1' = nullmat(`mu_1'), A[1,1]
mat `mu_2' = nullmat(`mu_2'), A[1,2]
mat `mu_3' = nullmat(`mu_3'), A[1,3]
mat `mu_4' = nullmat(`mu_4'), A[1,4]
sum `var' `if' & TD1 == 1
mat `n1' = nullmat(`n1'), e(N)
sum `var' `if' & TD2 == 1
mat `n2' = nullmat(`n2'), e(N)
sum `var' `if' & TD3 == 1
mat `n3' = nullmat(`n3'), e(N)
sum `var' `if' & TD4 == 1
mat `n4' = nullmat(`n4'), e(N)
reg `var' i.`by' `if', robust
matrix B=r(table)
mat `b_1' = nullmat(`b_1'), B[1,2]
mat `b_2' = nullmat(`b_2'), B[1,3]
mat `b_3' = nullmat(`b_3'), B[1,4]
mat `p_1' = nullmat(`p_1'), B[4,2]
mat `p_2' = nullmat(`p_2'), B[4,3]
mat `p_3' = nullmat(`p_3'), B[4,4]
}
}
foreach mat in mu_1 mu_2 mu_3 mu_4 b_1 b_2 b_3 p_1 p_2 p_3 n1 n2 n3 n4 {
mat coln ``mat'' = `varlist'
}
eret local cmd "balancetable"
foreach mat in mu_1 mu_2 mu_3 mu_4 b_1 b_2 b_3 p_1 p_2 p_3 n1 n2 n3 n4 {
eret mat `mat' = ``mat''
}
end
Please focus on the mat `n_i' section. Thanks so much!
Here, I would want the N to corresponds to the number of observation for each treatment group. However, it does not seem to be that way, it keeps giving me the total number of observation in each wave (Not in each wave and each treatment group).
Can you please help me identify how I can change this:
capt prog drop balancetable
program balancetable, eclass
syntax varlist if, by(varname)
marksample touse
markout `touse' `by'
tempname mu_1 mu_2 mu_3 mu_4 b_1 b_2 b_3 p_1 p_2 p_3 n1 n2 n3 n4
capture drop TD*
tab `by', gen(TD)
foreach var of local varlist {
* Full Sample
cap confirm variable `var'
if _rc == 0 {
*cap assert !missing(`var')
*if _rc == 0 {
reg `var' TD1 TD2 TD3 TD4 `if', nocons
matrix A=e(b)
mat `mu_1' = nullmat(`mu_1'), A[1,1]
mat `mu_2' = nullmat(`mu_2'), A[1,2]
mat `mu_3' = nullmat(`mu_3'), A[1,3]
mat `mu_4' = nullmat(`mu_4'), A[1,4]
sum `var' `if' & TD1 == 1
mat `n1' = nullmat(`n1'), e(N)
sum `var' `if' & TD2 == 1
mat `n2' = nullmat(`n2'), e(N)
sum `var' `if' & TD3 == 1
mat `n3' = nullmat(`n3'), e(N)
sum `var' `if' & TD4 == 1
mat `n4' = nullmat(`n4'), e(N)
reg `var' i.`by' `if', robust
matrix B=r(table)
mat `b_1' = nullmat(`b_1'), B[1,2]
mat `b_2' = nullmat(`b_2'), B[1,3]
mat `b_3' = nullmat(`b_3'), B[1,4]
mat `p_1' = nullmat(`p_1'), B[4,2]
mat `p_2' = nullmat(`p_2'), B[4,3]
mat `p_3' = nullmat(`p_3'), B[4,4]
}
}
foreach mat in mu_1 mu_2 mu_3 mu_4 b_1 b_2 b_3 p_1 p_2 p_3 n1 n2 n3 n4 {
mat coln ``mat'' = `varlist'
}
eret local cmd "balancetable"
foreach mat in mu_1 mu_2 mu_3 mu_4 b_1 b_2 b_3 p_1 p_2 p_3 n1 n2 n3 n4 {
eret mat `mat' = ``mat''
}
end
Please focus on the mat `n_i' section. Thanks so much!
Comment