问题描述
在我的一个模型中,我使用 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'
}
在 esttab
或 estout
中,将有一行用于交互效应,一行用于主效应。这是一个粗略的解决方法,但通常可以完成工作。
这个问题应该在“Stata 如何命名估计器中的方程和系数”级别上解决。我改编了安德鲁的代码:
他正在使用 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
--------------------------------------------