我的 s 接收 Stata 的输入时出现问题threeparttable
。我以前用过,效果很好。但我稍微扭曲了一下表格,它就报错。
我想要一个带有面板的表格。每个面板有两个子列,每个子列有四个子子列。所以总共有 9 列,其中一列是变量名称,其余是模型名称。代码如下:
\begin{sidewaystable}[htbp!]
\begin{threeparttable}[b]
\setlength{\tabcolsep}{0pt}
\small
\caption{Generalized DD Models}\label{Tab: Results1}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}lcccccccc@{}}
\toprule\toprule
\multicolumn{1}{l}{} &
\multicolumn{9}{c}{Panel A - Without Controls} \addlinespace
\cmidrule{2-9}
\multicolumn{1}{l}{} &
\multicolumn{4}{c}{Simple DD} &
\multicolumn{4}{c}{PSM + DD} \\
\cmidrule{2-5}
\cmidrule{6-9}
\input{tabfig_MP/model1_5_dd_am12.tex}
\multicolumn{1}{l}{} &
\multicolumn{9}{c}{Panel B - With Controls} \addlinespace
\cmidrule{2-9}
\multicolumn{1}{l}{} &
\multicolumn{4}{c}{Simple DD} &
\multicolumn{4}{c}{PSM + DD} \\
\cmidrule{2-5}
\cmidrule{6-9}
\input{tabfig_MP/model1_6_dd_am12.tex} \\ \hline
\hline\hline
\end{tabular*}
\begin{tablenotes}[flushleft]
\footnotesize
\item \textit{Notes:}[1] Values in the brackets represent the standard errors. Standard errors is clustered at the school level. */**/*** denotes significance at the 10/5/1 percent.
\end{tablenotes}
\end{threeparttable}
\end{sidewaystable}
上面的代码中\input{tabfig_MP/model1_5_dd_am12.tex}
,和\input{tabfig_MP/model1_6_dd_am12.tex}
是来自 Stata 的输入文件。除了系数之外,它们实际上是相同的。下面,我提供了其中一个输入文件:
&\multicolumn{1}{c}{(1)} &\multicolumn{1}{c}{(2)} &\multicolumn{1}{c}{(3)} &\multicolumn{1}{c}{(4)} &\multicolumn{1}{c}{(5)} &\multicolumn{1}{c}{(6)} &\multicolumn{1}{c}{(7)} &\multicolumn{1}{c}{(8)} \\
& Test Score &Passing Rate &Top University &Participation Rate & Test Score &Passing Rate &Top University &Participation Rate \\
\hline
Treated & -5.74 & -0.34 & -0.09 & -4.63 & -18.88 & -5.62 & -3.04 & -5.31 \\
& (7.53) & (2.66) & (1.16) & (4.78) & (12.10) & (4.15) & (1.93) & (6.98) \\
Post & 55.99***& 18.53***& 2.10***& 28.91***& 57.74***& 18.50***& 1.10 & 31.72***\\
& (3.72) & (1.28) & (0.57) & (2.52) & (10.57) & (3.71) & (1.64) & (5.17) \\
Treated X Post & 41.54***& 13.88***& 6.04***& 12.39** & 39.40***& 14.32***& 7.27***& 8.09 \\
& (9.20) & (3.33) & (1.65) & (5.36) & (14.47) & (5.12) & (2.47) & (6.96) \\
Boys School & 35.74***& 9.46***& 2.69***& 27.22***& 28.66***& 8.06** & 2.36 & 25.36***\\
& (4.60) & (1.61) & (0.93) & (3.64) & (9.61) & (3.31) & (1.70) & (6.14) \\
Treated X Post X Boys school & -16.32* & -4.59 & 1.00 & -4.93 & -9.70 & -3.57 & 1.41 & -3.89 \\
& (9.55) & (3.71) & (2.38) & (8.02) & (13.15) & (4.97) & (2.85) & (9.50) \\
Girls School & -0.62 & -5.35***& -3.08***& 1.75 & 2.44 & -7.05* & -5.67***& 3.58 \\
& (4.96) & (1.69) & (0.72) & (3.49) & (13.46) & (4.25) & (1.70) & (6.56) \\
Treated X Post X Girls School & -48.05***& -14.79***& -6.01***& -21.05** & -50.81** & -13.06* & -3.47 & -22.11** \\
& (17.17) & (5.69) & (2.16) & (9.29) & (21.54) & (6.95) & (2.67) & (11.01) \\
Constant & 76.84***& 25.10***& 8.16***& 19.35***& 90.08***& 29.93***& 10.93***& 20.76***\\
& (4.14) & (1.40) & (0.63) & (3.14) & (11.16) & (3.73) & (1.58) & (6.10) \\
\hline
R-squared & 0.27 & 0.26 & 0.10 & 0.16 & 0.32 & 0.31 & 0.15 & 0.22 \\
Total Obs & 1158 & 1158 & 1158 & 1052 & 421 & 421 & 421 & 401 \\
当我运行包含库和必要包的主文件时,它显示extra alignment tab has been changed to cr.
。我确信问题不在我的输入文件上,因为它在其他上下文中有效。如果有人能帮我解决这个问题,我将不胜感激。
答案1
除了考虑@Mico 评论(解决您的问题)之外,我还将使用列并使用同名包中定义的命令S
编写列标题:makecell
\documentclass{article}
\usepackage{rotating}
\usepackage{booktabs, makecell, threeparttable}
\usepackage{siunitx}
\begin{document}
\begin{sidewaystable}
\begin{threeparttable}[b]
\setlength{\tabcolsep}{0pt}
\small
\caption{Generalized DD Models}
\label{Tab: Results1}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}l
*{8}{S[table-format=-2.2,
table-space-text-post={$^{***})},
input-symbols={( )}] }}
\toprule
\multicolumn{1}{l}{} &
\multicolumn{8}{c}{Panel A - Without Controls} \\
\addlinespace
\cmidrule{2-9}
& \multicolumn{4}{c}{Simple DD} & \multicolumn{4}{c}{PSM + DD} \\
\cmidrule{2-5}
\cmidrule{6-9}
%\input{tabfig_MP/model1_5_dd_am12.tex}
& \multicolumn{8}{c}{Panel B - With Controls} \\
% \addlinespace
\cmidrule{2-9}
& \multicolumn{4}{c}{Simple DD} & \multicolumn{4}{c}{PSM + DD} \\
\cmidrule{2-5}
\cmidrule{6-9}
%\input{tabfig_MP/model1_6_dd_am12.tex} \\ \hline
& {\makecell{(1)\\Test\\ Score}}
& {\makecell{(2)\\Passing\\ Rate}}
& {\makecell{(3)\\Top\\ University}}
& {\makecell{(4)\\Participation\\ Rate}}
& {\makecell{(5)\\Test\\ Score}}
& {\makecell{(6)\\Passing\\ Rate}}
& {\makecell{(7)\\Top\\ University}}
& {\makecell{(8)\\Participation\\ Rate}} \\
\midrule
Treated & -5.74 & -0.34 & -0.09 & -4.63
& -18.88 & -5.62 & -3.04 & -5.31 \\
& (7.53) & (2.66) & (1.16) & (4.78)
& (12.10) & (4.15) & (1.93) & (6.98) \\
Treated X Post
& 41.54\tnote{***} & 13.88\tnote{***} & 6.04\tnote{***} & 12.39\tnote{**}
& 39.40\tnote{***} & 14.32\tnote{***} & 7.27\tnote{***} & 8.09 \\
& (9.20) & (3.33) & (1.65) & (5.36)
& (14.47) & (5.12) & (2.47) & (6.96) \\
\midrule
\end{tabular*}
\begin{tablenotes}[flushleft]
\footnotesize
\item \textit{Notes:}[1] Values in the brackets represent the standard errors. Standard errors is clustered at the school level. */**/*** denotes significance at the 10/5/1 percent.
\end{tablenotes}
\end{threeparttable}
\end{sidewaystable}
\end{document}
答案2
这是一个非常类似的解决方案@Zarko 的解决方案,主要区别如下:由于您不使用任何\tnote
指令,tablenotes
因此无需使用环境。简而言之,threeparttable
包装器被省略,因为它不做任何有用的事情。
该解决方案还结合了我之前发表的评论。
\documentclass{article}
\usepackage{rotating,booktabs,makecell,siunitx}
\sisetup{table-space-text-post = ***,
table-align-text-post = false,
input-symbols={()} }
\begin{document}
\begin{sidewaystable}
\setlength{\tabcolsep}{0pt}
\small
\caption{Generalized DD Models\strut}
\label{Tab:Results1}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}
l *{8}{S[table-format=-2.2]} }
\toprule
% & \multicolumn{8}{c}{Panel A --- Without Controls}\\
% \cmidrule{2-9}
% & \multicolumn{4}{c}{Simple DD} & \multicolumn{4}{c}{PSM + DD} \\
% \cmidrule{2-5} \cmidrule{6-9}
% %\input{tabfig_MP/model1_5_dd_am12.tex}
% \\
& \multicolumn{8}{c}{Panel B --- With Controls}\\
\cmidrule{2-9}
& \multicolumn{4}{c}{Simple DD} & \multicolumn{4}{c}{PSM + DD} \\
\cmidrule{2-5} \cmidrule{6-9}
%\input{tabfig_MP/model1_6_dd_am12.tex} \\
& {(1)} & {(2)} & {(3)} & {(4)}
& {(5)} & {(6)} & {(7)} & {(8)} \\
& {\makecell{Test\\ Score}} & {\makecell{Passing\\ Rate}}
& {\makecell{Top\\University}} & {\makecell{Participation\\Rate}}
& {\makecell{Test\\ Score}} & {\makecell{Passing\\ Rate}}
& {\makecell{Top\\University}} & {\makecell{Participation\\Rate}}
\\
\midrule
Treated & -5.74 & -0.34 & -0.09 & -4.63 & -18.88 & -5.62 & -3.04 & -5.31 \\
& (7.53) & (2.66) & (1.16) & (4.78) & (12.10) & (4.15) & (1.93) & (6.98) \\
Post & 55.99***& 18.53***& 2.10***& 28.91***& 57.74***& 18.50***& 1.10 & 31.72***\\
& (3.72) & (1.28) & (0.57) & (2.52) &(10.57) & (3.71) & (1.64) & (5.17) \\
Treated $\times$ Post & 41.54***& 13.88***& 6.04***& 12.39** & 39.40***& 14.32***& 7.27***& 8.09 \\
& (9.20) & (3.33) & (1.65) & (5.36) &(14.47) & (5.12) & (2.47) & (6.96) \\
Boys School & 35.74***& 9.46***& 2.69***& 27.22***& 28.66***& 8.06** & 2.36 & 25.36***\\
& (4.60) & (1.61) & (0.93) & (3.64) & (9.61) & (3.31) & (1.70) & (6.14) \\
Treated $\times$ Post $\times$ Boys school & -16.32* & -4.59 & 1.00 & -4.93 & -9.70 & -3.57 & 1.41 & -3.89 \\
& (9.55) & (3.71) & (2.38) & (8.02) &(13.15) & (4.97) & (2.85) & (9.50) \\
Girls School & -0.62 & -5.35***& -3.08***& 1.75 & 2.44 & -7.05* & -5.67***& 3.58 \\
& (4.96) & (1.69) & (0.72) & (3.49) &(13.46) & (4.25) & (1.70) & (6.56) \\
Treated $\times$ Post $\times$ Girls School & -48.05***& -14.79***& -6.01***& -21.05** & -50.81** & -13.06* & -3.47 & -22.11** \\
&(17.17) & (5.69) & (2.16) & (9.29) &(21.54) & (6.95) & (2.67) &(11.01) \\
Constant & 76.84***& 25.10***& 8.16***& 19.35***& 90.08***& 29.93***& 10.93***& 20.76***\\
& (4.14) & (1.40) & (0.63) & (3.14) &(11.16) & (3.73) & (1.58) & (6.10) \\
\midrule
R-squared & 0.27 & 0.26 & 0.10 & 0.16 & 0.32 & 0.31 & 0.15 & 0.22 \\
Total Obs & {1158} & {1158} & {1158} & {1052} & {421} & {421} & {421} & {401} \\
\bottomrule
\end{tabular*}
\medskip
\textit{Notes}: Values in parentheses represent standard errors.
Standard errors are clustered at the school level.
*/**/*** denote statistical significance at the 10/5/1 percent levels.
\end{sidewaystable}
\end{document}
答案3
您的回答非常有帮助。我使用 stata 中的 esttab 生成您手动编辑以回答我的问题的回归文件。由于我有几个回归表并且经常更改,我想知道是否有办法指示 Stata 仅根据您的编辑输出下面回归表的一部分。
Treated & -5.74 & -0.34 & -0.09 & -4.63 & -18.88 & -5.62 & -3.04 & -5.31 \\
& (7.53) & (2.66) & (1.16) & (4.78) & (12.10) & (4.15) & (1.93) & (6.98) \\
Post & 55.99***& 18.53***& 2.10***& 28.91***& 57.74***& 18.50***& 1.10 & 31.72***\\
& (3.72) & (1.28) & (0.57) & (2.52) &(10.57) & (3.71) & (1.64) & (5.17) \\
Treated $\times$ Post & 41.54***& 13.88***& 6.04***& 12.39** & 39.40***& 14.32***& 7.27***& 8.09 \\
& (9.20) & (3.33) & (1.65) & (5.36) &(14.47) & (5.12) & (2.47) & (6.96) \\
Boys School & 35.74***& 9.46***& 2.69***& 27.22***& 28.66***& 8.06** & 2.36 & 25.36***\\
& (4.60) & (1.61) & (0.93) & (3.64) & (9.61) & (3.31) & (1.70) & (6.14) \\
Treated $\times$ Post $\times$ Boys school & -16.32* & -4.59 & 1.00 & -4.93 & -9.70 & -3.57 & 1.41 & -3.89 \\
& (9.55) & (3.71) & (2.38) & (8.02) &(13.15) & (4.97) & (2.85) & (9.50) \\
Girls School & -0.62 & -5.35***& -3.08***& 1.75 & 2.44 & -7.05* & -5.67***& 3.58 \\
& (4.96) & (1.69) & (0.72) & (3.49) &(13.46) & (4.25) & (1.70) & (6.56) \\
Treated $\times$ Post $\times$ Girls School & -48.05***& -14.79***& -6.01***& -21.05** & -50.81** & -13.06* & -3.47 & -22.11** \\
&(17.17) & (5.69) & (2.16) & (9.29) &(21.54) & (6.95) & (2.67) &(11.01) \\
Constant & 76.84***& 25.10***& 8.16***& 19.35***& 90.08***& 29.93***& 10.93***& 20.76***\\
& (4.14) & (1.40) & (0.63) & (3.14) &(11.16) & (3.73) & (1.58) & (6.10) \\
\midrule
R-squared & 0.27 & 0.26 & 0.10 & 0.16 & 0.32 & 0.31 & 0.15 & 0.22 \\
Total Obs & {1158} & {1158} & {1158} & {1052} & {421} & {421} & {421} & {401} \\