latex - 使用 esttab 创建并排汇总统计表

标签 latex stata

我正在尝试创建一个包含不同分类变量的汇总统计表。

这是我通过社区贡献命令esttab成功实现的:

enter image description here

我使用的代码如下:

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/

相关文章:

latex - 如果使用 BibTex,如何手动均衡 IEEE 论文中的列?

Stata:原假设中均差不等于 0 的 t 检验

Stata:计数时忽略缺失值

python - 从 Stata 迁移到 Python

python - 将代码从 vim 发送到外部应用程序以执行

github - 潘多克 : set document title to first title

matlab - 在 Matlab 中创建 2D 频谱图

latex - 自 Xetex 弃用以来,使用 Pandoc 将 Markdown 转换为 PDF

emacs - AUCTex 问题中的预览

stata - 如何在 Stata 中对局部宏进行子集化