1
$\begingroup$

I found a paper on the effects of immigration on house prices, it uses fixed effects as a model. When looking at the results I found that the models use region fixed effects while some use year fixed effects but some use something called region-year fixed effects. what is the difference? and how can this be done in r?

here is a picture of the results(focus on the highlighted part)

enter image description here

To clarify my question, my concern is that how can the model be region and year fixed effects and be region-year fixed effects at the same time.

$\endgroup$
2
  • 1
    $\begingroup$ Pls. Could you provide the reference for the paper? $\endgroup$ – Jesper for President May 15 '20 at 8:27
  • $\begingroup$ Here is a link to the paper (you can find this table in the robustness section)--> lup.lub.lu.se/luur/… $\endgroup$ – Mourad Alkalza May 15 '20 at 8:39
2
$\begingroup$

You can include dummies (binary variables that are either 1 or 0) for each year, for each region, and also year times region interaction dummies in your model. So you might have a dummy for year 2019, another dummy for Northeast region, and then a dummy that is 1 for Northeastern region municipalities in 2019, and so on.

There are more computationally clever ways of doing that, but that's the basic idea.

$\endgroup$
5
  • 1
    $\begingroup$ Is it possible for you to elaborate on these more computational clever ways? (Maybe just a reference) I have a hard time seeing how you escape a dummy variable trap when you include them all at the same time. But I guess I am missing something? $\endgroup$ – Jesper for President May 15 '20 at 8:26
  • $\begingroup$ Yes it would be great to elaborate please $\endgroup$ – Mourad Alkalza May 15 '20 at 10:23
  • $\begingroup$ @JesperforPresident It depends on the structure of the panel. If your data is houses nested in regions, there is no dummy variable trap (assuming you omit one year and region as the base). You definitely can't have house, year, and house x year FEs at the same time (unless you do some sort of regularization). $\endgroup$ – Dimitriy V. Masterov May 15 '20 at 18:01
  • $\begingroup$ @MouradAlkalza The solution I suggested is easy unless the factors have too many levels (lots of regions and years). The R package lfe solves this problem by implementing a generalization of the within transformation to multiple large factors. There are probably others as well, since there are several possible generalizations. Look for "high-dimensional linear fixed effects". $\endgroup$ – Dimitriy V. Masterov May 15 '20 at 18:11
  • $\begingroup$ Maybe I am misunderstanding what approach you are suggesting @Dimitriy but I still believe there is a dummy trap, see my answer to the question. $\endgroup$ – Jesper for President May 15 '20 at 21:04
4
$\begingroup$

The dataset under consideration is a dataset for $i=1,...,I$ municipalities for $t=1,...,T$ time periods. The model to be estimated is

$$ y_{it} = \mathbf x_{it}^\top \beta + \delta_t + \phi_r + \psi_{rt} + \epsilon_{it},$$

where $\delta_t$ is time fixed effect, $\phi_r$ is the region fixed effect and $\psi_{rt}$ is region-time. To estimate this model under the assumption that $\delta_t , \phi_r , \psi_{rt}$ are effects portentially corrrelated with $\mathbf x_{it}$, as is standard the case when econometricians use the term "fixed-effects" you use the estimation equation

$$ y_{it} = \mathbf x_{it}^\top \beta + \lambda_{rt} + \epsilon_{it},$$

to get consistent estimates of $\beta$. This is the same as including a (time $\times$ region) dummy and this is the same as including the interaction between the time and the region dummy, while leaving both the time and the region dummy themselves out.

If you introduce both time, region and time-region dummies you have perfect multicollinearity.

Estimation in R can be performed using lfe package or lm if not many times and regions. Here is simulation code throwing NA's due to multicollinearity and a warning in lfe ...

Here is a simulation

library(data.table)
N <- 200
R <- 10
T <- 10


NN <- N*T 
dt <- data.table(id=rep(1:N,each=10),time=rep(1:T,N),x=rnorm(NN))
dt[,region:=sample(1:R,1),by=id]
dt[,region_eff:=rnorm(R)[region]]
dt[,time_eff:=rnorm(T)[time]]
dt[,time_region:=as.numeric(interaction(time,region))]
dt[,y:=2*x + time_eff + region_eff + time_region + rnorm(NN)]



lm(y~x+as.factor(time)+as.factor(region),data=dt)
lm(y~x+as.factor(time)+as.factor(region)+as.factor(time_region),data=dt)
lm(y~x+as.factor(time_region),data=dt)

library(lfe)
m1 <- felm(y~x|time+region,data=dt)
m2 <- felm(y~x|time+region+time_region,data=dt)
getfe(m2)

The reason why the lfe package only throws a warning when is explained in the documentation.

$\endgroup$
9
  • $\begingroup$ Try lm(y~x+as.factor(time)+as.factor(region) +as.factor(time):as.factor(region),data=dt). $\endgroup$ – Dimitriy V. Masterov May 15 '20 at 21:26
  • 1
    $\begingroup$ I think the way you coded it, R does not drop the right number of time x region interactions since it does not know that the time x region variable is a product of the other two. You should have 1 intercept, 1 $\beta_x$ slope, 9 region, 9 time, and 81 time x region coefficients. The as.factor(time_region) approach seems to try putting in 99 dummies instead, of which 18 are collinear given that region and time are also in the model. lm(formula = y ~ x + as.factor(time) * as.factor(region), data = dt) should also work. $\endgroup$ – Dimitriy V. Masterov May 15 '20 at 22:01
  • $\begingroup$ My point is exactly that you have to impose some sort of identifying restriction(s) in the model where you have time, region and time x region fixed effects to avoid the dummy trap. You could just as well have done as I suggested and estimate with 99 area x time and one constant. R imposes id. Restriction by removing some time x region interactions, thereby imposing they are 0. $\endgroup$ – Jesper for President May 16 '20 at 6:37
  • $\begingroup$ Maybe you were aware of this all the time and take it to be triviel, but I just thought it was not really clear in your original answer. If you use R the way you suggest software solves the problem. But lfe does not. So some user awareness of this problem is to be preferred (my opinion). $\endgroup$ – Jesper for President May 16 '20 at 6:47
  • $\begingroup$ I mostly agree, but I don’t see how what I am proposing is any different than dropping one omitted category for each categorical variable, which is inherited by time x region interactions. Calling that an identifying restriction that avoids perfect multicollinearity makes it sound more exotic and arbitrary that it truly is. Your model does not include separate time, region, and time x region FEs per se, but it will yield identical slope coefficients and predictions, which is what matters here. I think my approach is more transparent for what that thesis does, but this is a matter of taste. $\endgroup$ – Dimitriy V. Masterov May 16 '20 at 7:03

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.