Search code examples
regressionpanelstata

Fe and first difference in a regression table


I am doing an analysis in Stata and I have a lot of different panel regressions (within, first-difference and random trend) and to see the results properly, I am using eststo and esttab.

My problem now is that to get the difference for first difference and the double difference for the random trend, I use d.varname and d.d.varname. Stata then thinks that the differences are new variables and puts them in their own rows which becomes very difficult to read.

Has anyone an idea how I can get a regression table in which Stata sees varname, d.varname and d.d.varname as the same variable?

My regression looks like this:

 foreach v in a aa aaa aaaa{
 qui eststo: xtreg `v' b b1 b2 b3 b4 b5 i.year, fe cluster(xy)
 qui eststo: xtreg `v' b b1 b2 b3 b4 b5 i.year if c>d, fe cluster(xy)
 qui eststo: reg d.`v' d.b d.b1 d.b2 d.b3 d.b4 d.b5 i.year, cluster(xy)
 qui eststo: reg d.`v' d.b d.b1 d.b2 d.b3 d.b4 d.b5 i.year if c>d, cluster(xy)
 qui eststo: reg d.d.`v' d.d.b d.d.b1 d.d.b2 d.d.b3 d.d.b4 d.d.b5 i.year, cluster(xy)
 qui eststo: reg d.d.`v' d.d.b d.d.b1 d.d.b2 d.d.b3 d.d.b4 d.d.b5 i.year if c>d, cluster(xy)
 esttab using output.tex, wide
 }

In my table I then get my estimates for

 b
 b1
 b2
 b3
 b4
 b5
 d.b1
 d.d.b1
 d.b2
 d.d.b2
 and so on..

Solution

  • This is a bit hacked together--ultimately it doesn't do anything fancy but just automates the changing of variable names across specifications. It seems a bit too much code for such a simple question, but I don't know of an easier way to do this.

    ***create dummy data
    set seed 99
    webuse xtsetxmpl, clear
    foreach i in "" 1 2 3 4 5 {
        g b`i' = uniform()
        }
    foreach i in a aa aaa aaaa c d {
        g `i'= y*uniform()
        }
    *next two lines just so the differencing works
    g xy = pid
    replace tod = (tod-1609570800000)/(36*100000)
    xtset pid tod
    ***end of data creation
    
    cap program drop diff
    program define  diff
    syntax anything
    cap drop *_adj *adjDV
    if "`anything'" == "orig" {
    foreach i in "" 1 2 3 4 5 {
        g b`i'_adj = b`i'
        }
    foreach i in a aa aaa aaaa {
        g `i'_adjDV = `i'
        }
    }
    else {
    foreach i in "" 1 2 3 4 5 {
        g b`i'_adj = `anything'b`i'
        }
    foreach i in a aa aaa aaaa {
        g `i'_adjDV = `anything'`i'
        }
    }
     end
     **************************************
     *run original regression (excluding year term not necessary to example)
     **************************************
     eststo clear
     foreach v in a aa aaa aaaa {
     diff orig
     eststo: xtreg `v'_adjDV *adj , fe cluster(xy)
     eststo: xtreg `v'_adjDV *adj  if c>d, fe cluster(xy)
     diff d.
     eststo: reg `v'_adjDV *adj , cluster(xy)
     eststo: reg `v'_adjDV *adj  if c>d, cluster(xy)
     diff d.d.
     eststo: reg `v'_adjDV *adj , cluster(xy)
     eststo: reg `v'_adjDV *adj  if c>d, cluster(xy)
     esttab _all, wide
     }
    

    You are new here, so just for the future, try to post a MWE (minimal working example)---it makes things a bit quicker on this end. You can see that I have given an example of how to do this in the first section of the code.