首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用esttab创建具有可变均值和差异的表

问使用esttab创建具有可变均值和差异的表
EN

Stack Overflow用户
提问于 2019-01-12 22:34:44
回答 1查看 1.1K关注 0票数 0

我想在Stata中生成一个表,其中包含4个不同组的平均值、差值和t值。

特别是,假设您有2x2研究设计,并希望显示结果变量的平均值和标准差,并添加另一列来测试处理一的差异,以及另一行包含处理二的差异和t值。

我有以下代码:

代码语言:javascript
复制
clear
sysuse auto
gen large_trunk = (trunk > 14)
gen price_large_trunk = price if large_trunk == 1
gen price_small_trunk = price if large_trunk == 0

eststo price_domestic: qui estpost sum price_large_trunk price_small_trunk if foreign == 0
eststo price_foreign: qui estpost sum price_large_trunk price_small_trunk if foreign == 1
eststo diff: qui estpost ttest price_large_trunk price_small_trunk, by(foreign)
eststo diff2: qui estpost ttest price if foreign == 0, by(large_trunk)
eststo diff3: qui estpost ttest price if foreign == 1, by(large_trunk)

esttab price_domestic price_foreign diff diff2 diff3, ///
cells("mean(pattern(1 1 0) fmt(2)) b(star pattern(0 0 1) fmt(2))" "sd(pattern(1 1 0) par)  t(pattern(0 0 1) par)") ///
mtitle("Domestic" "Foreign" "Difference") ///
nonumbers  noobs ///
coeflabels(price "Difference") ///
notes 

输出为:

代码语言:javascript
复制
----------------------------------------------------------------------------------------------------------------
                 Domestic      Foreign   Difference           diff2                        diff3                
                  mean/sd      mean/sd          b/t         mean/sd          b/t         mean/sd          b/t   
----------------------------------------------------------------------------------------------------------------
price_larg~k      6900.13      6186.00       714.13                                                             
                (3164.76)    (2186.93)       (0.48)                                                             
price_smal~k      4850.57      6443.12     -1592.55                                                             
                (2608.98)    (2794.83)      (-1.81)                                                             
Difference                                                              -2049.56*                      257.12   
                                                                         (-2.45)                       (0.19)   
----------------------------------------------------------------------------------------------------------------

如您所见,这是一个7x3表。理想情况下,我希望将最后一行中的元素放在第一列和第二列中,并丢弃第三列之后的所有列。

另外,我还想知道是否可以在表头中隐藏汇总统计信息(我指的是处理名称下的mean/sd和b/t )。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-12 23:36:30

您需要修改代码,如下所示:

代码语言:javascript
复制
sysuse auto, clear
est clear
gen large_trunk = (trunk > 14)
gen price_large_trunk = price if large_trunk == 1
gen price_small_trunk = price if large_trunk == 0

qui estpost sum price_large_trunk price_small_trunk if foreign == 0
qui ttest price if foreign == 0, by(large_trunk)
estadd local diff2  `= round(r(mu_1) - r(mu_2), .01)'
estadd local tdiff2 (`= round(`r(t)', .01)')
eststo price_domestic

qui estpost sum price_large_trunk price_small_trunk if foreign == 1
qui ttest price if foreign == 1, by(large_trunk)
estadd local diff2 `= round(r(mu_1) - r(mu_2), .01)'
estadd local tdiff2 (`= round(`r(t)', .01)')
eststo price_foreign

eststo diff1: qui estpost ttest price_large_trunk price_small_trunk, by(foreign)

esttab price_domestic price_foreign diff1, ///
stats(diff2 tdiff2, label("Difference" " ") ) ///
cells("mean(pattern(1 1 0) fmt(2)) b(star pattern(0 0 1) fmt(2))" "sd(pattern(1 1 0) par)  t(pattern(0 0 1) par)") ///
mtitle("Domestic" "Foreign" "Difference") collabels(none) ///
nonumbers  noobs ///
coeflabels(price "Difference") ///
notes 

结果:

代码语言:javascript
复制
------------------------------------------------------
                 Domestic      Foreign   Difference   
------------------------------------------------------
price_larg~k      6900.13      6186.00       714.13   
                (3164.76)    (2186.93)       (0.48)   
price_smal~k      4850.57      6443.12     -1592.55   
                (2608.98)    (2794.83)      (-1.81)   
------------------------------------------------------
Difference       -2049.56       257.12                
                  (-2.45)        (.19)                
------------------------------------------------------

或者:

代码语言:javascript
复制
esttab price_domestic price_foreign diff1, ///
stats(diff2 tdiff2, label("Difference" " ") ) ///
cells("mean(pattern(1 1 0) fmt(2)) b(star pattern(0 0 1) fmt(2))" "sd(pattern(1 1 0) par)  t(pattern(0 0 1) par)") ///
mtitle("Domestic" "Foreign" "Difference") collabels(none) ///
nonumbers  noobs ///
coeflabels(price "Difference") ///
notes gaps prefoot(" ")

------------------------------------------------------
                 Domestic      Foreign   Difference   
------------------------------------------------------
price_larg~k      6900.13      6186.00       714.13   
                (3164.76)    (2186.93)       (0.48)   

price_smal~k      4850.57      6443.12     -1592.55   
                (2608.98)    (2794.83)      (-1.81)   

Difference       -2049.56       257.12                
                  (-2.45)        (.19)                
------------------------------------------------------

或者甚至是:

代码语言:javascript
复制
esttab price_domestic price_foreign diff1, ///
stats(diff2 tdiff2, label("Difference" " ") ) ///
cells("mean(pattern(1 1 0) fmt(2)) b(star pattern(0 0 1) fmt(2))" "sd(pattern(1 1 0) par)  t(pattern(0 0 1) par)") ///
mtitle("Domestic" "Foreign" "Difference") collabels(none) ///
nonumbers  noobs ///
coeflabels(price "Difference") ///
notes gaps plain 

                 Domestic      Foreign   Difference   

price_larg~k      6900.13      6186.00       714.13   
                (3164.76)    (2186.93)       (0.48)   

price_smal~k      4850.57      6443.12     -1592.55   
                (2608.98)    (2794.83)      (-1.81)   

Difference       -2049.56       257.12                
                  (-2.45)        (.19)                
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54160564

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档