1
votes

The estpost and esttab commands are from the estout package on SSC.

I use estpost summarize to make summary statistics tables. I am told that readers prefer decimals as fixed width/precision. Say, a leading zero and three decimal places. Option fmt(%9.3f) gives a leading zero and fixed width, but reports large numbers without commas. Option fmt(%12.3gc) gives commas, but does not report fixed width decimals.

Is there a way to be more granular with fmt() in esttab? Say, use %12.3gc for numbers above some threshold and %9.3f otherwise? This may create problems that I have not anticipated.

Here is an example of how I use estpost summarize and the shortcomings of each approach.

sysuse auto, clear
expand 1000

eststo clear
estpost summarize price rep78, detail
eststo

/* gives mean/median/SD with fixed number of decimals */
/* but must manually add commas to large numbers (price) */
local rightwidth_nocommas ///
    label noobs nonumbers nomtitles ///
    cell("count(fmt(%9.3gc) label(Obs.)) mean(fmt(%9.3f) label(Mean)) p50(fmt(%9.3f) label(Median)) sd(fmt(%9.3f) label(Std. Dev.))")
esttab, `rightwidth_nocommas'

. esttab, `rightwidth_nocommas'

------------------------------------------------------------------------
                             Obs.         Mean       Median    Std. Dev.
------------------------------------------------------------------------
Price                      74,000     6165.257     5006.500     2929.519
Repair Record 1978         69,000        3.406        3.000        0.983
------------------------------------------------------------------------



/* gives commas to large numbers (price) */
/* but must pad mean/median/SD to get a fixed number of decimals */
local commas_wrongwidth ///
    label noobs nonumbers nomtitles ///
    cell("count(fmt(%9.3gc) label(Obs.)) mean(fmt(%9.3gc) label(Mean)) p50(fmt(%9.3gc) label(Median)) sd(fmt(%9.3gc) label(Std. Dev.))")
esttab, `commas_wrongwidth'

. esttab, `commas_wrongwidth'

------------------------------------------------------------------------
                             Obs.         Mean       Median    Std. Dev.
------------------------------------------------------------------------
Price                      74,000        6,165        5,007        2,930
Repair Record 1978         69,000         3.41            3         .983
------------------------------------------------------------------------
1
So have you tried something like %9.3fc to get numbers with 3 places to the right of the decimal, and commas in large numbers to the left of the decimal? - user4690969
@WilliamLisowski Thanks. That (mostly) works in this context. I had tried %9.3fc before for N in the stats() option, but it didn't work (i.e., no comma, but fixed decimal). So for counts, %9.3fc in esttab gives XXXX.XXX (no comma), but for non-counts, %9.3fc in esttab gives X,XXX.XXX, which is what I want. TLDR use 9.3gc for counts, %9.3fc for everything else. - Richard Herron
@WilliamLisowski if you'd like the reputation, then make this an answer and I will mark as correct. Otherwise, I can answer. - Richard Herron

1 Answers

2
votes

Here's a demo using fc for everything, no gc needed for counts, and using a set of surrounding parentheses instead of quotation marks around the argument to cells to force the four items onto a single row.

. esttab, ///
>     label noobs nonumbers nomtitles               ///
>     cell((                                        ///
>            count(fmt(%9.0fc)  label(Obs.))        ///
>             mean(fmt(%10.3fc) label(Mean))        ///
>              p50(fmt(%8.1fc)  label(Median))      ///
>               sd(fmt(%10.3fc) label(Std. Dev.))   ///
>          ))

------------------------------------------------------------------------
                             Obs.         Mean       Median    Std. Dev.
------------------------------------------------------------------------
Price                      74,000    6,165.257      5,006.5    2,929.519
Repair Record 1978         69,000        3.406          3.0        0.983
------------------------------------------------------------------------