使用 siunitx 进行回归输出 - 对齐/列宽问题

使用 siunitx 进行回归输出 - 对齐/列宽问题

我的目标是建立一个回归表,其中的列按小数点分隔符对齐。

我生成了一个回归输出(使用 Stata)并使用用户编写的包将其导出esttab。在 LaTeX 中,我使用该包siunitx及其S列进行对齐。

但是,输出结果看起来很糟糕,表格没有正确处理括号中的不确定值(标准误差),系数和标准误差之间的差距太大。结果,一列中的标准误差覆盖了下一列中的系数。

有人知道如何从中得到一个美观的(和一致的)输出吗(理想情况下,不会引入太多额外的包或特殊的修复,因为这些会阻碍通过例程实现自动化esttab)?我试过separate-uncertaintyuncertainty-separator和其他选项,但都无济于事。

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

LaTeX 输出:

输出

答案1

您可能没有意识到,自然科学中以表格形式显示“不确定性”度量的方式与回归结果的统计报告方式截然不同。siunitx默认情况下,它适合自然科学的做事方式。但在回归表中,标准误差通常显示在单独的行中,以下相应的系数。

无论如何,我建议您将标准错误放在单独的行上。

另一条评论:由于所有数字似乎都已四舍五入到小数点后两位,因此选项round-mode = placesround-precision = 2似乎不需要。

在此处输入图片描述

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

答案2

以下是我的建议:

在此处输入图片描述

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

答案3

再次感谢您的有益建议。

最后,我发现了另一种方法来获得我想要的东西dcolumn。为了使其正常工作,我必须在回归输出中的回归系数和标准误差之间添加小空格(子句incelldelimite("\:")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

相关内容