Stata 14:在esttab中混合后的组数

时间:2016-03-21 17:43:15

标签: stata multi-level

我正在使用"混合"运行多级随机拦截模型。 STATA 14 / SE中的命令,我用esttab导出结果。我无法弄清楚如何将第二级组的数量添加到输出中,在我的情况下,它非常重要。如果我运行ereturn列表,我似乎无法找到组的数量,即使Stata在混合命令之后显示它。

以下是代码示例:

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

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:2)

使用estadd将返回矩阵N_g中第二级组的数量添加为 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]

然后只需将其与其余必需的标量一起输入esttab

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   
------------------------------------------------------------------------------------