formatting - 具有均值的 esttab 中的子组
问题描述
这是我尝试过的Stata代码:
eststo clear
sysuse auto, clear
eststo Dom: estpost sum rep78 mpg turn trunk weight length if foreign==0
eststo For: estpost sum rep78 mpg turn trunk weight length if foreign==1
esttab Dom For, cells("mean(fmt(2))" "sd") ///
nonumber nodepvars noobs se collabels(none) mlabels(, lhs("Var") title)
下面也是输出:
--------------------------------------
Var Dom For
--------------------------------------
rep78 3.02 4.29
0.84 0.72
mpg 19.83 24.77
4.74 6.61
turn 41.44 35.41
3.97 1.50
trunk 14.75 11.41
4.31 3.22
weight 3317.12 2315.91
695.36 433.00
length 196.13 168.55
20.05 13.68
--------------------------------------
这样做是使用 计算多个变量的均值和标准差summarize
。这是根据条件单独完成的(一次用于外国观察,一次用于非外国观察)。
然后通过 显示结果、平均值和标准差esttab
。我最终希望在 LaTeX 中得到它,但是为了简单起见,这个例子显示了 Stata 中的结果。
我有两个问题:
如何将标准偏差显示在括号中?
是否可以在变量之间包含任何行来分隔两个不同的组?
我有这样的想法:
--------------------------------------
Var Dom For
--------------------------------------
Variable Group 1:
--------------------------------------
rep78 3.02 4.29
(0.84) (0.72)
mpg 19.83 24.77
(4.74) (6.61)
turn 41.44 35.41
(3.97) (1.50)
--------------------------------------
Variable Group 2:
--------------------------------------
trunk 14.75 11.41
(4.31) (3.22)
weight 3317.12 2315.91
(695.36) (433.00)
length 196.13 168.55
(20.05) (13.68)
--------------------------------------
如果可能的话,我想使用eststo
等。我希望它尽可能自动化,但如果需要的话,我愿意将矩阵从 Stata 导出到 LaTeX 或使用片段。如果这是不可能的,我也愿意接受其他解决方案。
解决方案
关于第一个问题,您需要par
在sd
within中指定选项cells()
:
sysuse auto, clear
eststo clear
eststo Dom: estpost sum rep78 mpg turn trunk weight length if foreign==0
eststo For: estpost sum rep78 mpg turn trunk weight length if foreign==1
esttab Dom For, cells("mean(fmt(2))" "sd(par)") ///
nonumber nodepvars noobs se collabels(none) mlabels(, lhs("Var") title)
关于第二个问题,您可以执行以下操作:
eststo clear
eststo Dom: estpost sum rep78 mpg turn if foreign==0
eststo For: estpost sum rep78 mpg turn if foreign==1
esttab Dom For using output.txt, cells("mean(fmt(2))" "sd(par)") ///
nonumber nodepvars noobs collabels(none) mlabels(, lhs("Vars") title) ///
posthead("@hline" "Variable Group 1:" "@hline" ) postfoot(" ") replace
eststo clear
eststo Dom: estpost sum trunk weight length if foreign==0
eststo For: estpost sum trunk weight length if foreign==1
esttab Dom For using output.txt, cells("mean(fmt(2))" "sd(par)") ///
nonumber nodepvars noobs collabels(none) mlabels(none) ///
prehead("@hline" "Variable Group 2:") append
这将产生所需的输出:
type output.txt
--------------------------------------
Vars Dom For
--------------------------------------
Variable Group 1:
--------------------------------------
rep78 3.02 4.29
(0.84) (0.72)
mpg 19.83 24.77
(4.74) (6.61)
turn 41.44 35.41
(3.97) (1.50)
--------------------------------------
Variable Group 2:
--------------------------------------
trunk 14.75 11.41
(4.31) (3.22)
weight 3317.12 2315.91
(695.36) (433.00)
length 196.13 168.55
(20.05) (13.68)
--------------------------------------
推荐阅读
- c# - 在 rdlc 报告中创建序列号,但排除最后一行
- javascript - 如何在 html javascript 中使用此代码?克隆()
- android - 应用程序实例抛出空指针
- visual-studio-code - g++ 输出带有前导空格的文件名?
- mysql - 无法建立从工作台到 nodejs 的本地 mysql 连接
- java - POI 说 Cellstyle 是空的,但单元格有 Style
- plugins - 使用 WordPress 的新文本编辑器 Gutenberg 对齐文本的最佳方式?
- java - 如何使用 Apache HttpCient-5 Beta 正确执行 Http2
- javascript - 箭头没有显示在反应光滑的 4 多张照片中
- solidity - 向 MultiSigWallet.addOwner 交易错误:JsonRpcEngine - 响应没有错误或请求结果: