First, could someone explain in an easy way how nvals, _n and _N is used? I would like to count all distinct values of a variable and I have seen some codes online using
However, I have problems to understand what is done here.
Second, I have the following code for creating a balance table:
Can someone explain what is done above to create the table? I am new to Stata and get confused by these loops and _n, so it would be great if someone could explain it step by step. Also, is there an easier way to get the same table, but with a simpler code? Thanks.
Code:
by ...: gen nvals=_n=1
Second, I have the following code for creating a balance table:
Code:
local fixed v1 v2 v3 v4 v5
local fixed_n: word count `fixed'
forvalues i = 1 / `fixed_n' {
local fixed_name: word `i' of `fixed'
local fixed`i' : var label `fixed_name'}
foreach v of local fixed {
sum `v' if subset==1 }
*comparison 1
foreach v of local fixed {
xtreg `v' event_1 if subset==1, fe vce (cluster xfe)
outreg2 using Table1A}
*comparison 2
foreach v of local fixed {
xtreg `v' event_2 if subset==1, fe vce (cluster xfe)
outreg2 using Table1B}

Comment