Ziyu
Ziyu

Reputation: 57

Rounding summary statistics exported to LaTeX using esttab

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?

Upvotes: 0

Views: 4132

Answers (1)

user8682794
user8682794

Reputation:

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

Upvotes: 1

Related Questions