R:PLM-年固定收益-年和季度数据 [英] R: plm -- year fixed effects -- year and quarter data

查看:85
本文介绍了R:PLM-年固定收益-年和季度数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在设置面板数据模型时遇到问题.

以下是一些示例数据:

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)

我使用"id"作为个人指数并以"year"作为时间指数进行以下回归分析:

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

不幸的是,我收到以下错误:

pdim.default(index [[1]],index [[2]])中的重复对(time-id)错误:

为了解决这个问题,我使用了组合变量'y_q':

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

但这是我的问题-我只想具有固定年限的效果,而不是具有季度性的效果.

是否有另一种解决早期问题的方法,而不是使tiem索引为"y_q"?

提前感谢您的帮助!

解决方案

在面板设置中,每个夫妇id年通常没有重复值.

在四分之一的数据中,如果不汇总数据以使其成年,将很难计算出一年的固定效果模型.

此处中查看示例,以了解如何格式化数据以进行面板数据建模. /p>

在这里可以做到这一点:

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

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:

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]]) :

So to get around that, I use the combined variable that is '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'?

Thanks ahead of time for any help!

解决方案

In a panel setting, you usually don't have some duplicate value for each couple id-year.

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

这篇关于R:PLM-年固定收益-年和季度数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆