简体   繁体   English

R:PLM-年固定收益-年和季度数据

[英]R: plm — year fixed effects — year and quarter data

I am having a problem setting up a panel data model. 我在设置面板数据模型时遇到问题。

Here is some sample 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)

I run the following regression using 'id' as the individual index and 'year' as the time index: 我使用“ id”作为个人索引并使用“ year”作为时间索引运行以下回归:

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

Unfortunately, I get the following error: 不幸的是,我收到以下错误:

duplicate couples (time-id) Error in pdim.default(index[[1]], index[[2]]) : pdim.default(index [[1]],index [[2]])中的重复对(时间标识)错误:

So to get around that, I use the combined variable that is 'y_q': 因此,为了解决这个问题,我使用了组合变量'y_q':

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

But here's my issue -- I only want to have year fixed effects and not year-quarter. 但是,这是我的问题-我只希望具有固定年限的效果,而不是具有季度性的效果。

Is there another way to get around the earlier issue instead of making the tiem index 'y_q'? 是否有另一种解决早期问题的方法,而不是使tiem索引为“ y_q”?

Thanks ahead of time for any help! 提前感谢您的帮助!

In a panel setting, you usually don't have some duplicate value for each couple id-year. 在面板设置中,每个id年通常没有重复值。

In your quaterly data it will be difficult to compute a year fixed effect models without aggregating your data to make them yearly. 在您的四分之一数据中,如果不汇总数据以使其为每年,则很难计算出一年的固定效果模型。

Check the examples here to see how your data should be formatted for panel data modeling. 此处查看示例以了解如何格式化面板数据建模的数据。

Here is oneway to do that : 这是这样做的一种方法:

require(plyr)
yeardata  <- ddply(data, .(year, id), summarize, y = mean(y),
                                                 x = mean(x))


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

##      1999      2000 
## 0.2641997 0.0041193

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM