1
votes

I would like to be able to center a statistic over multiple columns when using esttab.

In my toy example, I would like N to span two columns:

sysuse auto, clear

est clear
qui estpost sum if foreign == 1
qui est store sum_foreign
qui estpost sum
qui est store sum_all

esttab sum_foreign sum_all, ///
    replace ///
    cells("mean(fmt(3)) sd(fmt(3))") ///
    nonum ///
    collabels("Mean" "SD") ///
    label ///
    noobs ///
    drop(make) ///
    stats(N, ///
        fmt(%9.0fc) ///
        label("Observations"))

Though the toy example just uses Stata's output, in general I would like to do this in LaTeX.

For other pieces of the table (collabels, mgroups etc.) you can specify the pattern() argument, which allows you to span, but this is not an option for stats().

Does anyone know how I can make the observation count span the width of the model (2 columns)?

1

1 Answers

1
votes

You need to manually insert the required spacing between each statistic with estadd, using the appropriate LaTeX markup as a prefix. This is necessary in order to typeset the table correctly.

The following works for me:

sysuse auto, clear

est clear
estpost sum if foreign == 1

local N1 \hspace{1.2cm}`e(N)'
estadd local NA `N1'

est store sum_foreign
estpost sum

local N2 \hspace{2cm}`e(N)'
estadd local NA `N2'

est store sum_all

esttab sum_foreign sum_all using table.tex, ///
    replace ///
    cells("mean(fmt(3)) sd(fmt(3))") ///
    nonum ///
    collabels("Mean" "SD") ///
    label ///
    noobs ///
    drop(make) ///
    stats(NA, ///
        fmt(%9.0fc) ///
        label("Observations"))

EDIT:

Here's another way of doing this but with automatic centering of the observation numbers:

sysuse auto, clear

est clear
estpost sum if foreign == 1

local N1 &\multicolumn{2}{c}{`e(N)'}

estadd local NA `N1'
est store sum_foreign

estpost sum

local N2 &\multicolumn{2}{c}{`e(N)'}

estadd local NA `N2'
est store sum_all

esttab sum_foreign sum_all using table.tex, ///
    replace ///
    cells("mean(fmt(3)) sd(fmt(3))") ///
    nonum ///
    collabels("Mean" "SD") ///
    label ///
    noobs ///
    drop(make) /// 
    postfoot("\hline Observations: `N1' `N2' \\ \hline\hline \\ \end{tabular} \\ }")