我正在尝试创建一个包含不同分类变量的汇总统计表。
这是我通过社区贡献命令esttab
成功实现的:
我使用的代码如下:
estpost tabstat diff_32 diff_43 diff_54 diff_42 diff_52 diff_53, ///
by(es) stat(mean sd) nototal columns(stat)
esttab . using "$tables/25_trial", replace cells(mean sd) tex label nogaps
但是,我需要的是并排的列,这样我的平均值就是主单元格,标准差作为辅助单元格。换句话说,每一列将包含一个分类变量,平均值和标准差位于同一单元格中。
如何产生所需的输出?
最佳答案
考虑以下玩具示例:
sysuse auto, clear
estpost tabstat price weight mpg, by(foreign) stat(mean sd) nototal columns(stat)
esttab ., cells(mean sd) label nogaps tex
{
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{tabular}{l*{1}{c}}
\hline\hline
&\multicolumn{1}{c}{(1)}\\
&\multicolumn{1}{c}{}\\
& mean/sd\\
\hline
Domestic & \\
Price & 6072.423\\
& 3097.104\\
Weight (lbs.) & 3317.115\\
& 695.3637\\
Mileage (mpg) & 19.82692\\
& 4.743297\\
\hline
Foreign & \\
Price & 6384.682\\
& 2621.915\\
Weight (lbs.) & 2315.909\\
& 433.0035\\
Mileage (mpg) & 24.77273\\
& 6.611187\\
\hline
Observations & 74\\
\hline\hline
\end{tabular}
}
只需使用 esttab
中的 unstack
选项即可获得所需的输出:
esttab ., cells(mean sd) label nogaps tex unstack
{
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{tabular}{l*{2}{c}}
\hline\hline
&\multicolumn{2}{c}{(1)} \\
&\multicolumn{2}{c}{} \\
& Domestic& Foreign\\
& mean/sd& mean/sd\\
\hline
Price & 6072.423& 6384.682\\
& 3097.104& 2621.915\\
Weight (lbs.) & 3317.115& 2315.909\\
& 695.3637& 433.0035\\
Mileage (mpg) & 19.82692& 24.77273\\
& 4.743297& 6.611187\\
\hline
Observations & 74& \\
\hline\hline
\end{tabular}
}
关于latex - 使用 esttab 创建并排汇总统计表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45981506/