Search code examples
stata

Adding name of control variables to esttab output


I would like to generate the following table with the community-contributed command esttab:

------------------------------------------------------------
                      (1)             (2)             (3)   
------------------------------------------------------------
rep78               2.384***        1.347*          1.149*  
                   (3.60)          (2.02)          (2.26)   

Other Cont~s         None      gear_ratio            size   

Foreign Co~s           No             Yes             Yes   
------------------------------------------------------------
N                      69              69              69   
------------------------------------------------------------

The closest that I could get to is the following:

------------------------------------------------------------
                      (1)             (2)             (3)   
------------------------------------------------------------
rep78               2.384***        1.347*          1.149*  
                   (3.60)          (2.02)          (2.26)   

Foreign Co~s           No             Yes             Yes   
------------------------------------------------------------
Other Cont~s         None      gear_ratio            size   
N                      69              69              69   
------------------------------------------------------------

The code that gets me there is below:

sysuse auto, clear
eststo clear

eststo: reg mpg rep78
estadd local other_control "None"

eststo: reg mpg foreign rep78 gear_ratio 
estadd local other_control "gear_ratio"

eststo: reg mpg foreign rep78 weight length 
estadd local other_control "size"

esttab, obslast nomtitles nomtitles nodepvars eqlabels(none) keep(rep78) ///
scalars("other_control Other Controls") indicate("Foreign Controls = foreign")

Any help would be appreciated.


Solution

  • The only way you can achieve the desired output is the following:

    sysuse auto, clear
    eststo clear
    
    eststo: reg mpg rep78
    eststo: reg mpg foreign rep78 gear_ratio 
    eststo: reg mpg foreign rep78 weight length 
    
    local OtherControls Other Controls{dup 7: }none{dup 6: }gear_ratio{dup 12: }size
    local ForeignControls Foreign Controls{dup 7: }no{dup 13: }yes{dup 13: }yes
    
    esttab, nomtitles keep(rep78) ///
    prefoot(`" "' `"`OtherControls'"' `" "' `"`ForeignControls'"' `"{hline 60}"')
    
    ------------------------------------------------------------
                          (1)             (2)             (3)   
    ------------------------------------------------------------
    rep78               2.384***        1.347*          1.149*  
                       (3.60)          (2.02)          (2.26)   
    
    Other Controls       none      gear_ratio            size
    
    Foreign Controls       no             yes             yes
    ------------------------------------------------------------
    N                      69              69              69   
    ------------------------------------------------------------