【问题标题】:Create regression tables with estout/esttab for interactions in Stata使用 estout/esttab 为 Stata 中的交互创建回归表
【发布时间】:2021-07-20 21:05:59
【问题描述】:

在我的一个模型中,我使用 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 无关。

【问题讨论】:

    标签: regression stata interaction


    【解决方案1】:

    对于多种不同的交互术语,您可以在回归之前重命名交互术语。例如,为了通过不同的协变量估计异构治疗效果,您可以运行:

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

    esttab或@ 487654323 @ @ @互动效果将有一行,以及主要效果的一行。这是一个粗暴的解决方法,但通常是工作。

    【讨论】:

    • 如果我为varlist生成相同的名称,请不要get variable interaction already defined span>
    • 嗨@mar​​co,是 - 我编辑了剪掉的代码以纠正该代码! span>
    【解决方案2】:

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

    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   
    --------------------------------------------
    

    【讨论】:

    【解决方案3】:

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多