Announcement

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

  • reghdfe extrapolation fitted values

    Dear all,

    I am comparing the fitted values obtained from reg and reghdfe (ssc install reghdfe). Following the approach described in https://www.statalist.org/forums/for...-after-reghdfe, I find that the fitted values from reg and from reghdfe are almost identical but not exactly the same.

    Code:
    ************************************************************************************
    ** reg and reghdfe fitted value comparison
    ************************************************************************************
    // no extrapolation
    // with singleton
    sysuse auto, clear
    bysort rep78: drop if rep78==4 & _n>1 // force rep78 == 4 to be singleton
    
    * reg
    reg price weight length i.rep78
    predict reg_fit_singleton, xb
    
    * reghdfe
    reghdfe price weight length, absorb(rep78) nocons res
    predict reghdfe_fit_singleton, xbd
    drop *resid
    
    * reghdfe + keepsingletons
    reghdfe price weight length, absorb(rep78) nocons res keepsingletons
    predict reghdfe_fit_singleton_keep, xbd
    drop *resid
    My first question is: are these differences simply due to numerical precision issues?

    Next, I would like to compute extrapolation fitted values in a similar way. I estimate the model using the sample with gear_ratio < 3, and then calculate the fitted values for the observations with gear_ratio ≥ 3 based on that estimation. With reg, it is straightforward to obtain the extrapolated fitted values, but reghdfe does not seem to allow this—likely because it has already absorbed the fixed effects.

    Code:
    ************************************************************************************
    ** reg and reghdfe fitted value "Extrapolation" comparison
    ************************************************************************************
    // extrapolation
    // with singleton
    sysuse auto, clear
    bysort rep78: drop if rep78==4 & _n>1 // force rep78 == 4 to be singleton
    
    * reg
    reg price weight length i.rep78 if gear_ratio < 3
    predict reg_fit if gear_ratio >= 3, xb
    
    * reghdfe + keepsingletons
    reghdfe price weight length if gear_ratio < 3, absorb(rep78) nocons res keepsingletons
    predict reghdfe_fit if gear_ratio >= 3, xbd
    drop *resid
    So my second question is: is there a way to use reghdfe to obtain extrapolation fitted values in the same way as reg?

  • #2
    Dear Frank Huang,

    For the first part of your question, using the option double when you predict helps, which suggests that these are just numerical issues. For the second part, see if this trick helps.

    Best wishes,

    Joao

    Comment


    • #3
      Dear Joao Santos Silva ,

      Thank you very much for your suggestions. This completely resolves the issue I was facing.

      Comment

      Working...
      X