我想使用 esttab
( ssc install estout
)按组生成汇总统计信息,其中包含平均差异和显着性的列 . 使用 estpost
, summarize
和 ttest
生成这两个单独的表很容易,并且手动组合,但我想自动完成整个过程 .
以下代码生成所需表的两个组件 .
sysuse auto, clear
* summary statistics by group
eststo clear
by foreign: eststo: quietly estpost summarize ///
price mpg weight headroom trunk
esttab, cells("mean sd") label nodepvar
* difference in means
eststo: estpost ttest price mpg weight headroom trunk, ///
by(foreign) unequal
esttab ., wide label
我可以打印两张 table 并将其粘贴到一张 table 上 .
* can generate similar tables and append horizontally
esttab, cells("mean sd") label
esttab, wide label
* manual, cut-and-paste solution
-------------------------------------------------------------------------------------------------------
(1) (2) (3)
mean sd mean sd
-------------------------------------------------------------------------------------------------------
Price 6072.423 3097.104 6384.682 2621.915 -312.3 (-0.44)
Mileage (mpg) 19.82692 4.743297 24.77273 6.611187 -4.946** (-3.18)
Weight (lbs.) 3317.115 695.3637 2315.909 433.0035 1001.2*** (7.50)
Headroom (in.) 3.153846 .9157578 2.613636 .4862837 0.540** (3.30)
Trunk space (.. ft.) 14.75 4.306288 11.40909 3.216906 3.341*** (3.67)
-------------------------------------------------------------------------------------------------------
Observations 52 22 74
-------------------------------------------------------------------------------------------------------
t statistics in parentheses
* p<0.05, ** p<0.01, *** p<0.001
似乎我应该能够通过一个 esttab
调用获得所需的表,而不需要剪切和粘贴,但我无法弄明白 . 有没有办法生成所需的表而无需手动切割和粘贴?
我宁愿输出一个LaTeX表,但任何消除剪切和粘贴的东西都是一大步,甚至是通过分隔的文本文件 .
3 回答
如果你仍然想使用esttab,你可以使用单元格和模式 . 可以使用以下代码复制原始帖子中的表:
产量
我没有
esttab
用esttab
(estout
包来自ssc
)这样做,但我有listtab
(也是ssc
)和postfile
的解决方案 . 这里的表与我上面提到的表略有不同,但是这种方法足够通用,你可以修改它以满足你的需要 .此解决方案还使用LaTeX的
booktabs
包 .这产生以下结果 .
选择的答案很好,但有点减少 . 只有estpost ttest才能达到相同的效果 .
输出如下所示: