[Tex/LaTex] Esttab, overriding decimal alignment

horizontal alignmenttables

This is a follow-up question to Estout and dcolumn: Overriding decimal alignment

In my case, using esttab, it centers the number of observations but it adds some decimals, for instance: Obersvations 3345.000, probably because I set se(3) or b(3) in the esttab command, which determine how many decimals are to be showed.

Any way to fix that?

esttab sex0 sex1 using men_women_aboradTTT.tex, stats(N,layout("\multicolumn{1{c}{@}") ///
    label("Observations")) se(3) b(3) ///
    noconstant label replace booktabs alignment(D{.}{.}{4,6}) ///

Best Answer

Include stats(N, fmt(%18.0g)into your esttab code.

Edit: Sorry, I did not see that you specify N to be into a multicolumn before. The following does the trick, and includes something more in additional, i.e. if you want R2 to be decimal aligned again with 3 decimal points after N (using siunitx, see below):

stats(N r2_p, fmt(0 3) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{S}{@}") labels(`"Observations"' `"Pseudo \(R^{2}\)"'))

I should add that I highly recommend switching to siunitx for decimal alignment. Have a look at Mico's answer:

And my two follow up questions:

Furthermore, I recommend using esttab with the fragment option (just include f in your esttab code). The table generated by esttab is then the pure table content, without headers and notes. I find when tables get a bit more complicated, esttab breaks them. You can avoid that with the fragment option.

When using the fragment option, include the following to your preamble:

\newcommand{\sym}[1]{\rlap{$#1$}} % Thanks to David Carlisle

\let\estinput=\input% define a new input command so that we can still flatten the document

\newcommand{\estwide}[3]{
        \vspace{.75ex}{
            \begin{tabular*}
                {\textwidth}{@{\hskip\tabcolsep\extracolsep\fill}l*{#2}{#3}}
            \toprule
            \estinput{#1}
            \bottomrule
            \addlinespace[.75ex]
            \end{tabular*}
            }
        }   

\newcommand{\estauto}[3]{
        \vspace{.75ex}{
            \begin{tabular}{l*{#2}{#3}}
            \toprule
            \estinput{#1}
            \bottomrule
            \addlinespace[.75ex]
            \end{tabular}
            }
        }

% Allow line breaks with \\ in specialcells
    \newcommand{\specialcell}[2][c]{%
    \begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}

% ********************************************************************
% Custom subcaptions
% ********************************************************************
% Note/Source/Text after Tables
\newcommand{\figtext}[1]{
    \vspace{-1.9ex}
    \captionsetup{justification=justified,font=footnotesize}
    \caption*{\hspace{6pt}\hangindent=1.5em #1}
    }
\newcommand{\fignote}[1]{\figtext{\emph{Note:~}~#1}}

\newcommand{\figsource}[1]{\figtext{\emph{Source:~}~#1}}

% Add significance note with \starnote  
\newcommand{\starnote}{\figtext{\sym{*} p < 0.1, \sym{**} p < 0.05, \sym{***} p < 0.01. Standard errors in parentheses.}}


% ********************************************************************
% siunitx customization
% ********************************************************************
\usepackage{siunitx} % centering in tables
    \sisetup{
        detect-mode,
        tight-spacing               = true,
        group-digits                = false ,
        input-signs             = ,
        input-symbols               = ( ) [ ] - + *,
        input-open-uncertainty  = ,
        input-close-uncertainty = ,
        table-align-text-post   = false 
        }

This creates two wrappers for esttab generated tables. \estwide uses tabular* and fills the table to the textwidth, \estauto uses tabular and uses the "standard" table width (i.e. width adjusted to your content).

The custom subcaptions are to include simple notes below the table using the caption package. You could then include a table as follows:

\begin{table}
    \caption{A really cool table} % The heading
    \estwide{table.tex}{2}{S[table-format=4.4]} % Include the table in the first bracket, the second bracket specifies the number of "data" columns and the third is for alignment (here using siunitx). The "4.4" specifies the decimals before and after the dot.
  % \estauto{table.tex}{2}{S[table-format=4.4]}
    \starnote % add description for significance stars 
    \figtext{\emph{Dependent Variable:} My dependent variable is cool}
    \fignote{Omitted groups: \emph{Employment:} Some dummies}
    \label{table}
\end{table}
Related Question