0

How can I deal with collinearity between a time variable and year fixed effects? I have a panel model where the outcome is measure in three separate years. I am using OLS from the fixest package.

One of the variables is gasprice. It takes the same value for every unit m in time period t.

The problem arises when I incorporate yearly fixed effects. R drops gasprice on account of multicollinearity.

I’ve tried re-running the model without the year fixed effects and respecifying gasprice as a factor variable (as.factor(gasprice))

Is there any way that I could keep gasprice and the year fixed effects without suffering from multicollinearity or having R drop gasprice?

Below some sample code to illustrate my issue.

Here is the data:

mydata <- data.frame(id=c(101,101,101,102,102,102),
year=c(1,2,3,1,2,3),
gasprice=c(70,80,75,70,80,75), 
treatment=c(4,2,1,7,8,9), 
outcome=c(12,3,1,6,7,11))

Here is the model with gasprice and the unit and year fixed effects:

panel1 <- feols(outcome ~ treatment + gasprice|id+year, 
               panel.id= ~id+year,
               se="HC1",
                               data=subset(mydata))

Here is the error message I get from R:

The variable 'gasprice' has been removed because of collinearity (see $collin.var).

Thank you

YouLocalRUser
  • 309
  • 1
  • 9
  • 1
    `gasprice` appears to _be_ a year fixed effect since it doesn't vary across `id`s, naturally it get's dropped. – jay.sf May 19 '22 at 05:22
  • 1
    It is simply that your model that is misspecified, you cannot have the two. It's like adding a gender (or anything time invariant) variable in a model with individual fixed-effects, it makes no sense since all the variation from that variable is captured by the FE. BTW `The variable ... has been removed etc` is not an error message. – Laurent Bergé May 19 '22 at 07:27

0 Answers0