time trends vs year fixed effects: is peaceful coexistence possible?

597 Views Asked by At

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

0

There are 0 best solutions below