对于面板数据摘要,有没有办法执行sutex或sutex2(从Stata格式编写汇总统计数据到.tex格式)?
答案 0 :(得分:2)
下面您可以找到一个实现,该实现使用 community-contributed 命令esttab
(类型为ssc install estout
的下载)来导出生成的(LaTeX
)桌子。
首先定义程序xtsum2
:
program define xtsum2, eclass
syntax varlist
foreach var of local varlist {
xtsum `var'
tempname mat_`var'
matrix mat_`var' = J(3, 5, .)
matrix mat_`var'[1,1] = (`r(mean)', `r(sd)', `r(min)', `r(max)', `r(N)')
matrix mat_`var'[2,1] = (., `r(sd_b)', `r(min_b)', `r(max_b)', `r(n)')
matrix mat_`var'[3,1] = (., `r(sd_w)', `r(min_w)', `r(max_w)', `r(Tbar)')
matrix colnames mat_`var'= Mean "Std. Dev." Min Max "N/n/T-bar"
matrix rownames mat_`var'= `var' " " " "
local matall `matall' mat_`var'
local obw `obw' overall between within
}
if `= wordcount("`varlist'")' > 1 {
local matall = subinstr("`matall'", " ", " \ ",.)
matrix allmat = (`matall')
ereturn matrix mat_all = allmat
}
else ereturn matrix mat_all = mat_`varlist'
ereturn local obw = "`obw'"
end
然后您可以运行xtsum2
并使用esttab
获得结果:
xtsum2 hours birth_yr
esttab e(mat_all), mlabels(none) labcol2(`e(obw)') varlabels(r2 " " r3 " ")
------------------------------------------------------------------------------------------
Mean Std. Dev. Min Max N/n/T-bar
------------------------------------------------------------------------------------------
hours overall 36.55956 9.869623 1 168 28467
between . 7.846585 1 83.5 4710
within . 7.520712 -2.154726 130.0596 6.043949
birth_yr overall 48.08509 3.012837 41 54 28534
between . 3.051795 41 54 4711
within . 0 48.08509 48.08509 6.056888
------------------------------------------------------------------------------------------
对于LaTeX
输出,只需添加tex
选项:
esttab e(mat_all), mlabels(none) labcol2(`e(obw)') varlabels(r2 " " r3 " ") tex
\begin{tabular}{lc*{5}{c}}
\hline\hline
& & Mean& Std. Dev.& Min& Max& N/n/T-bar\\
\hline
hours & overall & 36.55956& 9.869623& 1& 168& 28467\\
& between & .& 7.846585& 1& 83.5& 4710\\
& within & .& 7.520712& -2.154726& 130.0596& 6.043949\\
birth\_yr & overall & 48.08509& 3.012837& 41& 54& 28534\\
& between & .& 3.051795& 41& 54& 4711\\
& within & .& 0& 48.08509& 48.08509& 6.056888\\
\hline\hline
\end{tabular}