1

My goal is to have a regression table with columns aligned by the decimal separator.

I produced a regression output (using Stata) and exported it using the user-written package esttab. In LaTeX, I use the package siunitx and its S column for the alignment.

However, the output looks terrible, the table does not correctly handle the uncertainty values (standard errors) in brackets and there is too much of a gap between the coefficients and the standard errros. As a result, the standards errors in one column overlay the coefficients in the next column.

Would anybody know how to make a presentable (and aligned) output out of this (ideally without introducing too many extra packages or idiosyncratic repairs that would impede automation via the esttab routine)? I have tried playing around with separate-uncertainty, uncertainty-separator and other options to no avail.

% Key code in Latex
\usepackage{siunitx}
    \sisetup{
        input-signs             = -,
        input-symbols           = Yes,
        input-open-uncertainty  = ,
        input-close-uncertainty = ,
        round-mode              = places,
        round-precision         = 2,
        }

\begin{table}[!h]
  \centering
  \caption{XXX}
  \label{tab:4}
\begin{adjustbox}{max width=6in}
    \input{Table_4.tex}
\end{adjustbox}
\\[3pt]
\begin{minipage}{6in}
\footnotesize{Note: Significance levels: $^{+}\ p<0.1,  ^{*}\ p<0.05$, ^{**}\ p<0.01$, ^{***}\ p<0.001.$}
\end{minipage}
\end{table} \\

% Table output
{
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{tabular}{l S[table-format = 1.2(3),table-figures-uncertainty=1]   S[table-format = 1.2(3),table-figures-uncertainty=1] 
 S[table-format = 1.2(3),table-figures-uncertainty=1]}
\hline\hline
                        &\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}\\
                        &\multicolumn{1}{c}{\shortstack{\\IEF}}&\multicolumn{1}{c}{\shortstack{\\Contact}}&\multicolumn{1}{c}{\shortstack{\\Interaction}}\\
\hline
SUV                     &-0.38(0.09)\sym{***}&-0.49 (0.14)\sym{***}&-0.46 (0.19)\sym{*}  \\
SUV X Yes      &                     &                     &-0.33 (0.16)\sym{*}  \\
Yes            &                     & 0.30 (0.08)\sym{***}& 0.55 (0.13)\sym{***}\\
SUV X NO &                     &                     & 0.02 (0.26)         \\
NO &                     &-0.21 (0.24)         &-0.21 (0.36)         \\
Age                     & 0.09 (0.01)\sym{***}& 0.09 (0.01)\sym{***}& 0.09 (0.01)\sym{***}\\
Age²                    &-0.00 (0.00)\sym{***}&-0.00 (0.00)\sym{***}&-0.00 (0.00)\sym{***}\\
Female                  & 0.01 (0.03)         & 0.01 (0.03)         & 0.01 (0.03)         \\
Education: Primary      & 0.31 (0.11)\sym{**} & 0.30 (0.11)\sym{**} & 0.30 (0.11)\sym{**} \\
Education: Secondary    & 0.62 (0.12)\sym{***}& 0.61 (0.12)\sym{***}& 0.61 (0.12)\sym{***}\\
Education: Post-Secondary& 0.67 (0.11)\sym{***}& 0.67 (0.11)\sym{***}& 0.67 (0.11)\sym{***}\\
Education: University   & 1.13 (0.14)\sym{***}& 1.12 (0.14)\sym{***}& 1.12 (0.14)\sym{***}\\
Income: Quintile 2      & 0.16 (0.07)\sym{*}  & 0.16 (0.07)\sym{*}  & 0.16 (0.07)\sym{*}  \\
Income: Quintile 3      & 0.30 (0.06)\sym{***}& 0.30 (0.06)\sym{***}& 0.30 (0.06)\sym{***}\\
Income: Quintile 4      & 0.51 (0.05)\sym{***}& 0.51 (0.05)\sym{***}& 0.51 (0.05)\sym{***}\\
Income: Quintile 5      & 0.52 (0.10)\sym{***}& 0.52 (0.10)\sym{***}& 0.52 (0.10)\sym{***}\\
Small/Mid-Sized Town    &-0.10 (0.06)\sym{+}  &-0.10 (0.06)\sym{+}  &-0.10 (0.06)\sym{+}  \\
Suburb of a Large City  &-0.11 (0.06)\sym{+}  &-0.11 (0.06)\sym{+}  &-0.11 (0.06)\sym{+}  \\
Large City              &-0.11 (0.08)         &-0.11 (0.08)         &-0.11 (0.08)         \\
Close to a Party        & 0.98 (0.05)\sym{***}& 0.97 (0.05)\sym{***}& 0.97 (0.05)\sym{***}\\
Efficacy                & 0.34 (0.02)\sym{***}& 0.34 (0.02)\sym{***}& 0.34 (0.02)\sym{***}\\
Constant                &-4.05 (0.25)\sym{***}&-3.98 (0.23)\sym{***}&-4.01 (0.27)\sym{***}\\\hline
Country-Year Variance   & 0.04 (0.01)\sym{***}& 0.06 (0.03)\sym{+}  & 0.06 (0.03)\sym{+}  \\
\hline
Country FE              &\multicolumn{1}{c}{Yes}         &\multicolumn{1}{c}{Yes}         &\multicolumn{1}{c}{Yes}         \\
N (individuals)         &\multicolumn{1}{c}{75183}         &\multicolumn{1}{c}{75183}         &\multicolumn{1}{c}{75183}         \\
N (elections)           &\multicolumn{1}{c}{64}         &\multicolumn{1}{c}{64}         &\multicolumn{1}{c}{64}         \\
\hline\hline
\multicolumn{4}{l}{\footnotesize }\\
\end{tabular}
}

The LaTeX output:

Output

4
  • 1
    Welcome to TeX.SE!
    – Mensch
    Jul 22, 2020 at 10:09
  • From the code you showed so far, I assume, you get a lot of error messages if you try to compile it and the "output" you show is what you get from an unsuccessfull compilation. Please never ever ignore error messages! Even if you get something that on first glance resembles a pdf file, there can still be issues with it. After an error, TeX only tries to recover enough to syntax check more of the file, it does not try to make sensible output after an error.
    – leandriis
    Jul 22, 2020 at 10:39
  • What output do you expect from an input such as -0.38(0.09)\sym{***}?
    – leandriis
    Jul 22, 2020 at 11:21
  • Without siunitx (and the S column), it produces totally readable and presentable output. The only trouble is that it is not aligned by the decimal separator.
    – Creek
    Jul 22, 2020 at 11:35

3 Answers 3

1

It appears that you may not be aware that the ways that measures of "uncertainty" are displayed in tabular formats in the natural sciences is quite different from the ways employed in the statistical reporting of regression results. siunitx is geared, by default, to the natural sciences' ways of doing things. In regression tables, though, standard errors are usually displayed in separate rows, below the corresponding coefficients.

Anyway, I would recommend that you place the standard errors on separate rows.

Another comment: Since all numbers already appear to be rounded to two decimal digits, the options round-mode = places and round-precision = 2 don't seem to be needed.

enter image description here

\documentclass{article}
\usepackage{siunitx}
\sisetup{input-open-uncertainty  = ,
         input-close-uncertainty = ,
         table-space-text-pre    = (,
         table-space-text-post   = \sym{***},
         table-align-text-pre    = false,
         table-align-text-post   = false}
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\usepackage{booktabs}
\begin{document}

\begin{table}[!h]
\centering
\caption{XXX\strut}
\label{tab:4}

\begin{tabular}{@{} l *{3}{S[table-format = -1.2]} @{}}
\toprule
& {(1)} & {(2)}     & {(3)} \\
& {IEF} & {Contact} & {Interaction}\\
\midrule
SUV    &-0.38\sym{***}&-0.49 \sym{***}&-0.46 \sym{*}  \\
       & (0.09) & (0.14) & (0.19) \\
SUV$\times$Yes & & &-0.33\sym{*} \\
       & & &  (0.16) \\
Yes    & & 0.30 \sym{***}& 0.55 \sym{***}\\
       & & (0.08) & (0.13) \\
$\vdots$ \\
\midrule
Country FE          & {Yes}    & {Yes}   & {Yes}   \\
$N$ (individuals)   & {75183}  & {75183} & {75183} \\
$N$ (elections)     & {64}     & {64}    & {64}    \\
\bottomrule
\end{tabular}

\medskip\footnotesize 
Note: Significance levels: $^{+}\ p<0.1$,  $^{*}\ p<0.05$, $^{**}\ p<0.01$, $^{***}\ p<0.001$.

\end{table} 
\end{document}
1
  • 1
    Thanks for these clarifications! That's what I was afraid of and something that I would like to avoid for space management (I would really prefer having wide rather than long tables).
    – Creek
    Jul 22, 2020 at 11:41
1

Here is my suggestion:

enter image description here

\documentclass{article}

\usepackage{siunitx}
\usepackage{booktabs}


\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}

\begin{document}

\begin{table}[!h]
  \centering
  \caption{XXX}
  \label{tab:4}
\sisetup{table-space-text-post=\sym{***},
         table-align-text-post=false, 
         table-format = -1.2(3)}
\setlength{\tabcolsep}{0pt}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}lSSS}
\toprule
                           & {(1)}               & {(2)}              & {(3)}                \\
                           & {IEF}               & {Contact}          & {Interaction}        \\
\hline
SUV                        & -0.38 (9)\sym{***}  & -0.49 (14)\sym{***} & -0.46 (19)\sym{*}    \\
SUV X Yes                  &                     &                     & -0.33 (16)\sym{*}    \\
Yes                        &                     &  0.30 (8)\sym{***}  &  0.55 (13)\sym{***}  \\
SUV X NO                   &                     &                     &  0.02 (26)           \\
NO                         &                     & -0.21 (24)          & -0.21 (36)           \\
Age                        &  0.09 (1)\sym{***}  &  0.09 (1)\sym{***}  &  0.09 (1)\sym{***}   \\
Age²                       & -0.00 (0)\sym{***}  & -0.00 (0)\sym{***}  & -0.00 (0)\sym{***}   \\
Female                     &  0.01 (3)           &  0.01 (3)           &  0.01 (3)            \\
Education: Primary         &  0.31 (11)\sym{**}  &  0.30 (11)\sym{**}  &  0.30 (11)\sym{**}   \\
Education: Secondary       &  0.62 (12)\sym{***} &  0.61 (12)\sym{***} &  0.61 (12)\sym{***}  \\
Education: Post-Secondary  &  0.67 (11)\sym{***} &  0.67 (11)\sym{***} &  0.67 (11)\sym{***}  \\
Education: University      &  1.13 (14)\sym{***} &  1.12 (14)\sym{***} &  1.12 (14)\sym{***}  \\
Income: Quintile 2         &  0.16 (7)\sym{*}    &  0.16 (7)\sym{*}    &  0.16 (7)\sym{*}     \\
Income: Quintile 3         &  0.30 (6)\sym{***}  &  0.30 (6)\sym{***}  &  0.30 (6)\sym{***}   \\
Income: Quintile 4         &  0.51 (5)\sym{***}  &  0.51 (5)\sym{***}  &  0.51 (5)\sym{***}   \\
Income: Quintile 5         &  0.52 (10)\sym{***} &  0.52 (10)\sym{***} &  0.52 (10)\sym{***}  \\
Small/Mid-Sized Town       & -0.10 (6)\sym{+}    & -0.10 (6)\sym{+}    & -0.10 (6)\sym{+}     \\
Suburb of a Large City     & -0.11 (6)\sym{+}    & -0.11 (6)\sym{+}    & -0.11 (6)\sym{+}     \\
Large City                 & -0.11 (8)           & -0.11 (8)           & -0.11 (8)            \\
Close to a Party           &  0.98 (5)\sym{***}  &  0.97 (5)\sym{***}  &  0.97 (5)\sym{***}   \\
Efficacy                   &  0.34 (2)\sym{***}  &  0.34 (2)\sym{***}  &  0.34 (2)\sym{***}   \\
Constant                   & -4.05 (25)\sym{***} & -3.98 (23)\sym{***} & -4.01 (27)\sym{***}  \\
\midrule
Country-Year Variance      &  0.04 (1)\sym{***}  &  0.06 (3)\sym{+}    &  0.06 (3)\sym{+}     \\
\midrule
Country FE                 & {Yes}               & {Yes}               & {Yes}                \\
N (individuals)            & {75183}             & {75183}             & {75183}              \\
N (elections)              & {64}                & {64}                & {64}                 \\
\bottomrule
\multicolumn{4}{l}{\footnotesize Note: Significance levels: \sym{+} p<0.1,  \sym{*} p<0.05, \sym{**} p<0.01, \sym{***} p<0.001.}
\end{tabular*}
\end{table}

\end{document}
4
  • Thanks. This is very close to what I would need. But would it possible to get the full standard error (including the decimal separator) and a space between the coefficient and the standard error? When I tried to make such changes, the numerical result disappears (only the significance sign is displayed).
    – Creek
    Jul 22, 2020 at 12:03
  • With separate-uncertainties=true you can get i.stack.imgur.com/pM31b.png. Does this suit your needs?
    – leandriis
    Jul 22, 2020 at 12:08
  • If you want to get -0.38 (0.09)*** as the output instead of -0.38(9)*** or -0.38 +- 0.09***, use two columns, one for the number and a second for the error.
    – leandriis
    Jul 22, 2020 at 12:11
  • This solves my problem! Many thanks!
    – Creek
    Jul 22, 2020 at 12:25
0

Thanks agains for your helpful suggestions.

Finally, I found have another way to get what I want using dcolumn. To make it work properly, I had to add small spaces in the regression output between the regression coefficients and the standard errors (subption incelldelimite("\:") in esttab).

% Code

\documentclass[letterpaper,12pt]{article}
\usepackage[utf8]{inputenc}

\usepackage{adjustbox}
\usepackage{booktabs,subcaption,amsfonts,dcolumn} 
\newcolumntype{d}[1]{D..{#1}}

\begin{document}

\begin{table}[!h]
  \centering
  \caption{xxxx}
  \label{tab:4}
\begin{adjustbox}{max width=6in}
    \input{Table_4.tex}
\end{adjustbox}
\\[3pt]
\begin{minipage}{6in}
\footnotesize{Note: Hierarchical logistic regression with country fixed effects and random intercepts by election. Standard errors in parentheses. Significance levels: $^{+}\ p<0.1,  ^{*}\ p<0.05$, ^{**}\ p<0.01$, ^{***}\ p<0.001.$}
\end{minipage}
\end{table} \\


% Table
{
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{tabular}{l*{3}{d{10}}}
\hline\hline
                        &\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}\\
                        &\multicolumn{1}{c}{\shortstack{\\SUV}}&\multicolumn{1}{c}{\shortstack{\\Yes}}&\multicolumn{1}{c}{\shortstack{\\Interaction}}\\
\hline
SUV                     &-0.38\:(0.09)\sym{***}&-0.49\:(0.14)\sym{***}&-0.46\:(0.19)\sym{*}  \\
SUV X Contact: Yes      &          \:         &          \:         &-0.33\:(0.16)\sym{*}  \\
Yes            &          \:         &0.30\:(0.08)\sym{***}&0.55\:(0.13)\sym{***}\\
SUV X Contact: No       &          \:         &          \:         &0.02\:(0.26)         \\
No             &          \:         &-0.21\:(0.24)         &-0.21\:(0.36)         \\
Age                     &0.09\:(0.01)\sym{***}&0.09\:(0.01)\sym{***}&0.09\:(0.01)\sym{***}\\
Age^2                    &-0.00\:(0.00)\sym{***}&-0.00\:(0.00)\sym{***}&-0.00\:(0.00)\sym{***}\\
Female                  &0.01\:(0.03)         &0.01\:(0.03)         &0.01\:(0.03)         \\
Education: Primary      &0.31\:(0.11)\sym{**} &0.30\:(0.11)\sym{**} &0.30\:(0.11)\sym{**} \\
Education: Secondary    &0.62\:(0.12)\sym{***}&0.61\:(0.12)\sym{***}&0.61\:(0.12)\sym{***}\\
Education: Post-Secondary&0.67\:(0.11)\sym{***}&0.67\:(0.11)\sym{***}&0.67\:(0.11)\sym{***}\\
Education: University   &1.13\:(0.14)\sym{***}&1.12\:(0.14)\sym{***}&1.12\:(0.14)\sym{***}\\
Income: Quintile 2      &0.16\:(0.07)\sym{*}  &0.16\:(0.07)\sym{*}  &0.16\:(0.07)\sym{*}  \\
Income: Quintile 3      &0.30\:(0.06)\sym{***}&0.30\:(0.06)\sym{***}&0.30\:(0.06)\sym{***}\\
Income: Quintile 4      &0.51\:(0.05)\sym{***}&0.51\:(0.05)\sym{***}&0.51\:(0.05)\sym{***}\\
Income: Quintile 5      &0.52\:(0.10)\sym{***}&0.52\:(0.10)\sym{***}&0.52\:(0.10)\sym{***}\\
Small/Mid-Sized Town    &-0.10\:(0.06)\sym{+}  &-0.10\:(0.06)\sym{+}  &-0.10\:(0.06)\sym{+}  \\
Suburb of a Large City  &-0.11\:(0.06)\sym{+}  &-0.11\:(0.06)\sym{+}  &-0.11\:(0.06)\sym{+}  \\
Large City              &-0.11\:(0.08)         &-0.11\:(0.08)         &-0.11\:(0.08)         \\
Close to a Party        &0.98\:(0.05)\sym{***}&0.97\:(0.05)\sym{***}&0.97\:(0.05)\sym{***}\\
Efficacy                &0.34\:(0.02)\sym{***}&0.34\:(0.02)\sym{***}&0.34\:(0.02)\sym{***}\\
Constant                &-4.05\:(0.25)\sym{***}&-3.98\:(0.23)\sym{***}&-4.01\:(0.27)\sym{***}\\\hline
Country-Year Variance   &0.04\:(0.01)\sym{***}&0.06\:(0.03)\sym{+}  &0.06\:(0.03)\sym{+}  \\
\hline
Country FE              &\multicolumn{1}{c}{Yes}         &\multicolumn{1}{c}{Yes}         &\multicolumn{1}{c}{Yes}         \\
N (individuals)         &\multicolumn{1}{c}{75183}         &\multicolumn{1}{c}{75183}         &\multicolumn{1}{c}{75183}         \\
N (elections)           &\multicolumn{1}{c}{64}         &\multicolumn{1}{c}{64}         &\multicolumn{1}{c}{64}         \\
\hline\hline
\multicolumn{4}{l}{\footnotesize }\\
\end{tabular}
}



https://i.stack.imgur.com/dDG2P.png

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .