How to include a year fixed effect (in a year-quar

2019-09-04 09:47发布

问题:

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

回答1:

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.



标签: r plm