I'm trying to replicate in R the results of a paper that uses the Stata reghdfe command but keep running into some issues. I've attached the dataset I'm using here (5.49 MB).

Ultimately, I want to obtain the same results that these Stata commands output:

import delimited sample_data.csv, case(preserve)
xtset ID year
reghdfe y l(0/1).delta_t l(0/1).delta_p, absorb(i.fact i.year i.ID i.ID#c.year i.ID#c.year_sqr)

The coefficients produced are as follows:

  • delta_t = -0.00243
  • lag of delta_t = -0.00652
  • delta_p = 0.00175
  • lag of delta_p = 0.0195.

In R, I'd like to use the fixest package. I've posted an issue on the package's GitHub, but it got closed before I managed to fully test the answer. My R code is as follows:

data_fe <- data.table::fread('sample_data.csv')
data_fe_p <- panel(data_fe, ~ ID + year)
feols(y ~ l(delta_t, 0:1) + l(delta_p, 0:1) | fact + ID + year + ID[year, year_sqr], data = data_fe_p)

but this results in the following - quite different - coefficients:

  • delta_t = -0.000833
  • lag of delta_t = -0.004863
  • delta_p = 0.002202
  • lag of delta_p = 0.021593.

I can match the Stata output exactly if I remove the year_sqr interaction in both softwares, i.e., if I do reghdfe y l(0/1).delta_t l(0/1).delta_p, absorb(i.fact i.year i.ID i.ID#c.year) in Stata and feols(y ~ l(delta_t, 0:1) + l(delta_p, 0:1) | fact + ID + year + ID[year], data = data_fe_p).

Any idea how to include the interaction and match the outputs?

  • 1
    $\begingroup$ You've made the dataset accessible. Another way to pose the question is to post a tiny dataset within the question that makes the issue easily reproducible. It's my understanding that this kind of thing typically involves (very) large datasets, so that may seem absurd, but it's experience here that many people are reluctant to download large datasets, for all kinds of reasons, including their time and security issues. $\endgroup$
    – Nick Cox
    Oct 13 at 10:07
  • $\begingroup$ Perhaps try ID[year] + ID[year_sqr]? $\endgroup$
    – dimitriy
    Oct 14 at 0:37
  • $\begingroup$ @dimitriy, the notation ID[year, year_sqr] is just a shortcut for the expanded version you're suggesting. $\endgroup$
    – Skumin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.