Announcement

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

  • time trends by group with new HDFE commands

    Hi everyone,

    I'm using the new version of areg in Stata Now 19.5, and I am wondering if anyone has an idea of how I could take advantage of this command to absorb group specific time trends, just like reghdfe from SSC. I want to run something like this:

    Code:
    areg y x, absorb(i.group#c.time)
    Where
    time is any kind of time variable. The problem is that none of the new high-dimensional fixed effects (HDFE) commands allow factor-variable and time-series operators in absorb.

    If I add these time trends as variables, all the speed gains of the new HDFE commands disappear. Here is an example based on the HDFE announcement page:

    Code:
    webuse hdfe, clear
    
    timer clear
    
    timer on 1
    areg y x, absorb(id a1 a2)
    est sto m1
    timer off 1
    
    timer on 2
    reghdfe y x, abs(id a1 a2)
    est sto m2
    timer off 2
    
    timer list
    For me, the runtime of areg is 1/10 of the one of reghdfe. However, if I create a time variable, and add time trends for each group of the variable a1, then areg's runtime becomes 17 times the time that reghdfe takes to run:

    Code:
    bys id: gen time=_n
    timer on 3
    qui reghdfe y x, abs(id i.a1#c.time)
    timer off 3
    
    timer on 4
    qui areg y x i.a1#c.time, abs(id)
    timer off 4
    
    timer list
    Any ideas of how I could the new HDFE commands to add these time trends?

  • #2
    Hi everyone,

    I found an answer to my question, so I am replying to myself here. After looking at the source code for areg, I found out that the _hdfe_map_solve Mata function is the one that partials-out fixed effects, and you can use to partial-out any kind of variables. Unfortunately, doing this is slower than using reghdfe, or areg while controlling for time trends.

    Here is an example of how you can do this. You need to expand the factor variables with fvexpand and set the sample with touse. _hdfe_map_solve returns coefficients and the variance-covariance matrix in r(b) and r(V), so you could write a short program to get regressions results with ereturn post.


    Code:
    webuse hdfe, clear
    bys id: gen time=_n
    
    timer on 1
    qui reghdfe y x, abs(id i.a1#c.time)
    timer off 1
    
    timer on 2
    qui areg y x i.a1#c.time, abs(id)
    timer off 2
    
    gen touse=1
    fvexpand id i.a1#c.time
    timer on 3
    mata: _hdfe_map_solve("areg","y","x","touse","`r(varlist)'", 1, ("",""), (50,1.00000000000e-08,1, 0), "halperin","ols","")
    timer off 3
    
    timer list

    Comment

    Working...
    X