微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 estout/esttab 为 Stata 中的交互创建回归表

如何解决使用 estout/esttab 为 Stata 中的交互创建回归表

在我的一个模型中,我使用 Stata 中交互术语的标准内置符号,在另一个模型中,我必须手动编码。最后,我想使用 esttab 展示漂亮的回归表。如何在同一行中显示相同但编码略有不同的交互术语?或者想象一下,这实际上是另一种交互,我怎么能强迫 esttab 忽略它?

// interaction model 1
sysuse auto,clear
regress price weight c.mpg##c.mpg foreign 
estimates store model1

// interaction model 2
gen int_mpg_mpg = mpg*mpg
regress price weight mpg int_mpg_mpg foreign
estimates store model2  

// make nice regression table sidy-by-side

// manual label manual interactions
label variable int_mpg_mpg "Mileage (mpg) # Mileage (mpg)"
esttab model1 model2,label

// export to latex
label variable int_mpg_mpg "Mileage (mpg) $\times$ Mileage (mpg) "
esttab model1 model2 using "table.tex",/// 
label nobaselevels beta not interaction(" $\times$ ") style(tex) replace

输出到控制台:

enter image description here

输出到 LaTeX:

enter image description here

在这两种情况下,手册 variable label 在回归表中都显示名称。但是相同的变量名称不会在同一行中对齐。我对 LaTeX 输出解决方案更感兴趣,但问题似乎与 LaTeX 无关。

解决方法

esttab 将无法忽略类似的东西,因为变量的指定方式是独一无二的。我建议您以适用于两个规范(例如交互模型 2)的相同方式处理所有交互术语。

,

对于多个不同的交互项,您可以在回归之前重命名交互项本身。例如,要估计不同协变量的异质治疗效果,您可以运行:

foreach var of varlist age education {
   cap drop interaction
   gen interaction = `var'
   reg outcome i.treatment##c.interaction
   est store `var'
   }

esttabestout 中,将有一行用于交互效应,一行用于主效应。这是一个粗略的解决方法,但通常可以完成工作。

,

这个问题应该在“Stata 如何命名估计器中的方程和系数”级别上解决。我改编了安德鲁的代码:

https://www.statalist.org/forums/forum/general-stata-discussion/general/1551586-align-nls-and-mle-estimates-for-the-same-variable-in-the-same-row-esttab

他正在使用 SSC (erepost) 的 Ben Jann 的程序 ssc install erepost

* model 1
sysuse auto,clear
eststo clear
gen const=1
qui regress price weight c.mpg##c.mpg foreign
mat b=e(b)
* store estimates 
eststo model1 

* model 2 
gen int_mpg_mpg = mpg*mpg // generate interaction manually 
qui regress price weight mpg int_mpg_mpg foreign 

* rename interaction with additional package erepost 
local coln "b:weight b:mpg b:c.mpg#c.mpg b:foreign b:_cons"
mat colnames b= `coln'
capt prog drop replace_b
program replace_b,eclass
erepost b= b,rename
end
replace_b
eststo model2

esttab model1 model2,mtitle("Interaction V1" "Interaction V2")

现在,所有交互(自动和手动)都对齐了:

--------------------------------------------
                      (1)             (2)   
             Interactio~1    Interactio~2   
--------------------------------------------
main                                        
weight              3.038***        3.038***
                   (3.84)          (3.84)   

mpg                -298.1          -298.1   
                  (-0.82)         (-0.82)   

c.mpg#c.mpg         5.862           5.862   
                   (0.90)          (0.90)   

foreign            3420.2***       3420.2***
                   (4.62)          (4.62)   

_cons              -527.0          -527.0   
                  (-0.08)         (-0.08)   
--------------------------------------------
N                      74              74   
--------------------------------------------

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。