I am estimating a regression where I control for district and year fixed effects (hence using xtreg or reghdfe), while simultaneously examining the marginal effect of my binary variable X, which does NOT vary over time, just over districts. However, I wish to allow that marginal effect to vary over years.
Like many others, I have found that margins after xtreg (or it turns out reghdfe) is tricky.
I began with this code:
While I can see the interactions between x and year in my regression output, margins will not return the marginal effect of x over year ("not estimable").
Precisely this problem was documented here and Jeff Pitblado explains that we must not include the i.x fixed effect alone, as it does not vary within districts. He recommends that we instead run a regression like this, manually excluding i.x, but including the x-year interactions.
For the simple nlswork dataset example being discussed in that thread, margins works after this formulation. However, in my case, this does NOT solve the problem -- I get the same "not estimable" error as before. And I'm apparently not alone -- that thread ends with a plaintive cry from Peter Meier asking the same question that I'm asking now. Given that this is a classic DiD / event study type regression, loads of people must try it, to meet with this same problem. How do I solve this? (Happy to post the code + precise data if necessary.)
Two post-scripts: (1) I find precisely the same problem if I use "reghdfe y i.x#i.year i.year , absorb(district year)". (2) While Jeff Pitblado mentions in his reply that manually excluding i.x should not change results, I oddly find that the coefficient on one year level in my output changes across the two specifications listed above. The interaction coefficients change too, but that's to be expected since different interaction years are being dropped as omitted in those two formulations. But I find it odd that all year-specific (i.year) coefficients are identical across the two formulations, except for 1 of them, which is tiny (0.0000133) under the second formulation, but sizable (0.0437494) under the first.
Like many others, I have found that margins after xtreg (or it turns out reghdfe) is tricky.
I began with this code:
Code:
xtset district year xtreg y i.x##i.year , fe vce(bootstrap) margins, dydx(x) over(year)
Precisely this problem was documented here and Jeff Pitblado explains that we must not include the i.x fixed effect alone, as it does not vary within districts. He recommends that we instead run a regression like this, manually excluding i.x, but including the x-year interactions.
Code:
xtset district year xtreg y i.x#i.year i.year , fe vce(bootstrap) margins, dydx(x) over(year)
Two post-scripts: (1) I find precisely the same problem if I use "reghdfe y i.x#i.year i.year , absorb(district year)". (2) While Jeff Pitblado mentions in his reply that manually excluding i.x should not change results, I oddly find that the coefficient on one year level in my output changes across the two specifications listed above. The interaction coefficients change too, but that's to be expected since different interaction years are being dropped as omitted in those two formulations. But I find it odd that all year-specific (i.year) coefficients are identical across the two formulations, except for 1 of them, which is tiny (0.0000133) under the second formulation, but sizable (0.0437494) under the first.
Comment