问题
I am running multilevel random intercept models with the mixed
command in Stata 14
SE.
I want to export the results with the community-contributed command esttab
but I cannot figure out how to add the number of second level groups to the output, which in my case it's rather important.
More specifically, I cannot seem to find the number of groups if I run ereturn list
, even though Stata displays it after the mixed
command.
Here is an example of the code:
mixed defect c.cenretrosoc c.centrust i.wave || countrywave:
est sto H1A_
mixed defect c.centrust i.wave##c.cenretrosoc || countrywave:
est sto H1A_2
mixed defect c.cenretrosoc i.wave##c.centrust || countrywave:
est sto H1A_3
mixed defect i.wave##c.centrust##c.cenretrosoc || countrywave:
est sto H1A_4
esttab H1A_1 H1A_2 H1A_3 H1A_4 using "defect_all.rtf", b(a1) nobaselevels nocons aic bic ///
scalars("ll Log lik." "nrgroups") label title(Defection - EU members) interact(*) ///
nonumbers mtitles("Baseline" "Econ*Wave" "Misrep*Wave" "Econ*Misrep*Wave") ///
starlevels(~ 0.10 * 0.05 ** 0.01 *** 0.001) nonote replace
How can I do this?
回答1:
Use estadd
to add the number of second level groups from returned matrix N_g
as a
scalar in e()
:
webuse nlswork, clear
estimates clear
mixed ln_w age c.age#c.age tenure c.tenure#c.tenure || id:
estimates store H1A_1
matrix A = e(N_g)
estadd scalar ngrps = A[1,1]
mixed ln_w grade age tenure c.tenure#c.tenure || id:
estimates store H1A_2
matrix A = e(N_g)
estadd scalar ngrps = A[1,1]
mixed ln_w grade age c.age#c.age ttl_exp || id:
estimates store H1A_3
matrix A = e(N_g)
estadd scalar ngrps = A[1,1]
mixed ln_w grade age ttl_exp tenure || id:
estimates store H1A_4
matrix A = e(N_g)
estadd scalar ngrps = A[1,1]
Then simply feed this to esttab
with the rest of the required scalars:
esttab H1A_1 H1A_2 H1A_3 H1A_4, b(a1) nobaselevels nocons aic bic ///
scalars("ll Log lik." "ngrps") label title(My custom title) interact(*) ///
nonumbers mtitles("First" "Second" "Third" "Fourth") ///
starlevels(~ 0.10 * 0.05 ** 0.01 *** 0.001) nonote
My custom title
------------------------------------------------------------------------------------
First Second Third Fourth
------------------------------------------------------------------------------------
ln(wage/GNP deflat~)
age in current year 0.05*** 0.010*** 0.04*** -0.004***
(16.63) (26.17) (16.56) (-6.78)
age in current yea~e -0.0006*** -0.0009***
(-12.69) (-19.58)
job tenure, in years 0.05*** 0.05*** 0.01***
(29.95) (32.73) (15.96)
job tenure, in yea~, -0.002*** -0.002***
(-15.32) (-18.32)
current grade comp~d 0.08*** 0.07*** 0.07***
(42.11) (39.29) (41.23)
total work experie~e 0.04*** 0.03***
(43.82) (26.92)
------------------------------------------------------------------------------------
Observations 28101 28099 28508 28099
AIC 20726.5 19381.0 19263.8 19002.3
BIC 20784.2 19438.7 19321.6 19060.0
Log lik. -10356.3 -9683.5 -9624.9 -9494.2
ngrps 4699 4697 4708 4697
------------------------------------------------------------------------------------
来源:https://stackoverflow.com/questions/36138121/add-number-of-second-level-groups-in-esttab-after-mixed