使用 estout/esttab 创建回归表以在 Stata 中进行交互

Create regression tables with estout/esttab for interactions in 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

输出到控制台:

输出到 LaTeX:

在这两种情况下,手册 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 (ssc install erepost) 的 Ben Jann 的程序 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   
--------------------------------------------