Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exporting regression table to Latex with -esttab-: How to stack regressions vertically

    Hi everyone,

    I am running regressions for multiple y variables against multiple x variables. Trying to figure out the best way to automate exporting to Latex, so that the end results looks like the table below. That is, the columns are all the dependent variables, and the rows are different specifications stacked vertically.

    Click image for larger version

Name:	table.png
Views:	1
Size:	47.3 KB
ID:	1462520

    The way I am doing it right now involves a lot of manual copy-pasting, which is repetitive and error-prone. I'm running the following code with -esttab-, and copying segments of the tex outputs ("x1.tex", "x2.tex") to a new tex file to construct the table above. Is there a way to directly construct the table though? I think maybe the trick is to use the -append- option, but can't figure out how exactly to do it. Any help would be greatly appreciated!

    Code:
    sysuse auto, clear
    
    rename (weight length) (x1 x2)
    rename (price mpg headroom) (y1 y2 y3)
    
    local xlist x1 x2
    local ylist y1 y2 y3
    
    foreach x of local xlist {
        eststo clear
        foreach y of local ylist {
            eststo: reg `y' `x' 
            }
        esttab using "`x'.tex", label booktabs not nonotes nonumber r2 replace
        }

  • #2
    I think the following will more or less do it:

    Code:
    sysuse auto, clear
    
    rename (weight length) (x1 x2)
    rename (price mpg headroom) (y1 y2 y3)
    
    local xlist x1 x2
    local ylist y1 y2 y3
        eststo clear
    
    foreach x of local xlist {
        foreach y of local ylist {
            eststo reg_`x'_`y': reg `y' `x' 
            }
        }
    
    esttab reg_x1_y1 reg_x1_y2 reg_x1_y3 using "reg_test_tex.tex", label  fragment  replace
        
    esttab  reg_x2_y1 reg_x2_y2 reg_x2_y3 using "reg_test_tex.tex", label fragment  append
    I can't compile it on this pc, but the tex-fil looks acceptable, perhaps you need to work with the options on title and label?

    Comment

    Working...
    X