Rounding summary statistics exported to LaTeX using esttab

会有一股神秘感。 提交于 2020-01-30 08:56:24

问题


I want to export summary statistics table (mean, median, min, max, sd) to LaTeX using the community-contributed command esttab but rounding the reported statistics to two decimals.

Below is my Stata code:

eststo sumstats1: quietly estpost sum var1 var2 var3, detail

esttab sumstats1, cells("mean p50 min max sd") nonumbers label

esttab sumstats1 using "$repodir/output/tables/sumstats.tex", booktabs ///
       label nonumbers cells("mean p50 min max sd") replace 

My results show summary statistics but many have a long list of digits after the decimal.

Is there a way of specifying this in Stata?


回答1:


You need to specify the fmt() sub-option for each statistic in cell():

sysuse auto, clear
eststo clear

estpost summarize mpg

esttab, cells("mean(fmt(%8.2f))" "sd(fmt(%8.2f))")

-------------------------
                      (1)

                  mean/sd
-------------------------
mpg                 21.30
                     5.79
-------------------------
N                      74
-------------------------

Use the tex option for LaTeX output:

{
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{tabular}{l*{1}{c}}
\hline\hline
            &\multicolumn{1}{c}{(1)}\\
            &\multicolumn{1}{c}{}\\
            &     mean/sd\\
\hline
mpg         &       21.30\\
            &        5.79\\
\hline
\(N\)       &          74\\
\hline\hline
\end{tabular}
}


来源:https://stackoverflow.com/questions/57120352/rounding-summary-statistics-exported-to-latex-using-esttab

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!