How to include a year fixed effect (in a year-quarter panel data) in R using plm function?
Asked Answered
E

1

0

Thank you all in advance for your help. My question is essentially a "bump" of the following question: R: plm -- year fixed effects -- year and quarter data.

Basically, I was wondering if there is anyway using the plm function in R to include a fixed effect that is not at the same level as the data. For example, suppose you have the following data

library(plm)

id <- c(1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2)
year <- c(1999,1999,1999,1999,2000,2000,2000,2000,1999,1999,1999,1999,2000,2000,2000,2000)
qtr <- c(1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4)
y <- rnorm(16, mean=0, sd=1)
x <- rnorm(16, mean=0, sd=1)

data <- data.frame(id=id,year=year,qtr=qtr,y_q=paste(year,qtr,sep="_"),y=y,x=x)

This is a panel data set, with the cross sectional unit marked as "id" and the time unit at the year-quarter level. However, I only want to actually include a fixed effect for year, I do not want to include a fixed effect for year-quarter. However, if you try running this regression,

reg1 <- plm(y ~ x, data=data,index=c("id", "year"), model="within",effect="time")

I get the following error:

duplicate couples (time-id) Error in pdim.default(index[[1]], index[[2]]) :

Now, to add to the post I previously linked, if you are using a fixed effects model, one way to get around this is to manually put in the fixed effects as a vector of dummy variables, and just use pooled cross section regression. For example,

reg1 <- plm(y ~ x + factor(id) + factor(year), data=data,index=c("id", "year"), model="pooling",effect="time")

If that works for you, then great! However, this solution does not work for me because I definitely need to use the plm function. The reason why is because I actually want to put in a year random effect, and I'm not sure how to do that "manually". Is there a work around for this using the plm function?

Thanks!

Vincent

Ellora answered 1/3, 2015 at 3:29 Comment(3)
Panel data you created is not a panel data. There are multiple y{it}s for single (i,t), thus the error "duplicate couples". Use y_q as a time indexing. Also, it is always better to convert the time to proper time format.Cutty
So given this data, using the plm function, how would you include a year fixed effect, other than the "pooling" solution I added above (manually putting in the year FE dummy variables.Ellora
Aggregate your data, maybe?Cutty
C
0

You will need to make the combination of year and quarter the time dimension of your data set, i.e., use y_q as the second index variable.

This model: reg_q <- plm(y ~ x, data=data, index=c("id", "y_q"), model="within", effect="time") will take care of quartly effects only.

This model: reg_ind_year <- plm(y ~ x + factor(year), data=data, index=c("id", "y_q"), model="within", effect="individual") will take care of individual effects and yearly effects (note the inclusion of factor(year) in the model). It does no take quarterly effects into account.

Chinchy answered 17/8, 2017 at 15:51 Comment(1)
What format should the y_q data have, since I am struggling to create a time index fulfilling the requirements of plm with quarterly data.Henze

© 2022 - 2024 — McMap. All rights reserved.