Announcement

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

  • Generating a Latex Table with Line Breaks for Stored Coefficients

    Dear Statalisters,

    I am trying to figure out how to generate a latex table with my stored coefficients in a particular way. I would like to run regressions on first-difference (FD) and on fixed effects (FE) and display the estimated coefficients in a way that makes it easier to compare them. Hence, each column would have coefficients for regressions with the same specification in terms of controls, while each line would have coefficients obtained from the same "method" (FD or FE). Making myself clear, the table below illustrates what I am trying to do.
    (1) (2) (3)
    Beta FE 0.1 0.2 0.3
    Beta FD 0.05 0.03 0.09
    (1) has no controls
    (2) has temperature (or the first-difference of temperature) as a control
    (3) has temperature and rain (or the first-difference of temperature and rain) as controls

    By the way, I was planning to use keep() or any similar option in order to only display the coefficient I am interested in.

    In order to estimate the coefficients I have written a loop where I get the regressions I need done. and then I store the coefficients using different "names". For instance eststo bet_fe1 or eststo bet_fd1. I have been trying to generate a table like the one above by esttab, but could not figure out how to do it (if i just write esttab bet_fe* bet_fd* I do not have the coefficients displayed in the manner I want as the stored coefficients will be shown kinda* one next to other). I am open to solutions that do not use the esttab command or that require changes in my code, though. My guess is that I would have to find an option that would break the first line of estimates after the third estimate (hence, the title of my post).

    *As I am doing FE and FD i don't have the same dependent and independent variables, so they are not really on next to the other, but they are definety not shown one below the other.

    Thanks for the help,

    Roberto
    Last edited by Roberto Santos; 28 May 2018, 19:19.

  • #2
    Since I can't see your data I can't do exactly what you're asking, but you should be able to adapt the following example to what you need:

    Code:
    capt prog drop appendmodels
    
    *! version 1.0.0  14aug2007  Ben Jann
    program appendmodels, eclass
        // using first equation of model
        version 8
        syntax namelist
        tempname b V tmp
        foreach name of local namelist {
        qui est restore `name'
        mat `tmp' = e(b)
        local eq1: coleq `tmp'
          gettoken eq1 : eq1
          mat `tmp' = `tmp'[1,"`eq1':"]
        local cons = colnumb(`tmp',"_cons")
        if `cons'<. & `cons'>1 {
            mat `tmp' = `tmp'[1,1..`cons'-1]
        }
        mat `b' = nullmat(`b') , `tmp'
        mat `tmp' = e(V)
        mat `tmp' = `tmp'["`eq1':","`eq1':"]
        if `cons'<. & `cons'>1 {
            mat `tmp' = `tmp'[1..`cons'-1,1..`cons'-1]
        }
        capt confirm matrix `V'
        if _rc {
            mat `V' = `tmp'
        }
        else {
            mat `V' = ///
             ( `V' , J(rowsof(`V'),colsof(`tmp'),0) ) \ ///
             ( J(rowsof(`tmp'),colsof(`V'),0) , `tmp' )
            }
        }
        local names: colfullnames `b'
        mat coln `V' = `names'
        mat rown `V' = `names'
        eret post `b' `V'
        eret local cmd "whatever"
    end
    
    *-------------Begin Example--------------------
    clear
    sysuse auto
    
    // Note: You may need to do -ssc install lincomest- first, I can't remember
    
    qui reg price mpg 
    lincomest mpg 
    est store m1 
    
    qui reg price mpg rep78 
    lincomest mpg
    est store m2 
    
    qui reg price mpg rep78 headroom
    lincomest mpg
    est store m3 
    
    qui reg price mpg i.foreign
    lincomest mpg
    est store m1_fe 
    
    reg price mpg rep78 i.foreign
    lincomest mpg
    est store m2_fe 
    
    qui reg price mpg rep78 headroom i.foreign
    lincomest mpg
    est store m3_fe
    
    * Appending the models
    eststo m1_final: appendmodels m1 m1_fe
    eststo m2_final: appendmodels m2 m2_fe
    eststo m3_final: appendmodels m3 m3_fe
    
    esttab m1_final m2_final m3_final, keep(*)


    Comment

    Working...
    X