Announcement

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

  • Predicting counterfactual from reghdfe

    Dear Statlisters,

    I am trying to compute a counterfactual prediction if a certain explanatory variable had different values.

    Here is a simple example using the auto dataset:

    Code:
    sysuse auto
    
    // Run linear regression with fixed effects
    reghdfe price mpg, a(foreign) resid
    
    // Generate predicted values (requires "resid" option for previous command)
    predict price_prediction_actual, xbd
    
    // Adjust values for counterfactual
    replace mpg = 500
    
    // Generate counterfactual prediction (i.e., price estimate if all observed cars had driven exactly 500 miles)
    predict price_prediction_counterfactual, xbd
    Unfortunately, the two predictions are identical... so they do not reflect the adjustment to the mpg variable.

    This seems to be specific to the reghdfe command, since the following works:

    Code:
    sysuse auto
    reg price mpg i.foreign
    predict price_prediction_actual
    replace mpg = 500
    predict price_prediction_counterfactual
    I am somewhat forced to do this analysis with reghdfe. Therefore, does anyone know how to resolve this?

    Many thanks in advance and kind regards,
    John Hanser
    Last edited by John Hanser; 16 Jun 2022, 17:39.

  • #2
    John, you may try this: predict the counterfactual price with the "xb" option, and then add the prediction of actual absorbed effects to the counterfactual prediction.

    Code:
    sysuse auto
    
    // Run linear regression with fixed effects
    reghdfe price mpg, a(foreign) resid
    
    // Generate predicted values (requires "resid" option for previous command)
    predict price_prediction_actual, xbd
    predict absorb_actual, d
    
    // Adjust values for counterfactual
    replace mpg = 500
    
    // Generate counterfactual prediction (i.e., price estimate if all observed cars had driven exactly 500 miles)
    predict price_prediction_counterfactual, xb
    replace price_prediction_counterfactual = price_prediction_counterfactual + absorb_actual

    Comment


    • #3
      Originally posted by Fei Wang View Post
      John, you may try this: predict the counterfactual price with the "xb" option, and then add the prediction of actual absorbed effects to the counterfactual prediction.
      Thanks a lot, Fei. That perfectly worked.

      Comment

      Working...
      X