使用R和plm估算包含时间相互作用的固定效应模型


16

plm()用来估计形式的固定效应模型

y ~ x + time + time:fixed_trait

其中fixed_trait,变量在个体之间会有所不同,但在个体内部却是恒定的。

与之互动time的目的fixed_trait是使效果fixed_trait随时间变化。(我从Paul Allison的最新固定效果手册中从事此工作。引文附后。)

plm()毫不费力地估计此类模型的系数和标准误差。但是summary.plm()无法为这些模型计算R ^ 2。这是我要解决的问题。

这是一个最小的示例:

library(plm)
tmp <- data.frame(ID=rep(1:3, 2), year=rep(0:1, each=3), 
                  y=rnorm(6), const=rep(1:3, 2))
fe1 <- plm(y ~ year,              index=c('ID', 'year'), data=tmp)
fe2 <- plm(y ~ year + year:const, index=c('ID', 'year'), data=tmp)
summary(fe1)  # works fine
summary(fe2)  # Error in crossprod(t(X), beta) : non-conformable arguments

深入研究plm:::summary.plm可以使问题更加清楚。要计算R ^ 2,请plm尝试执行以下操作:

beta <- coef(fe2)
X <- model.matrix(fe2)
crossprod(t(X), beta)

这行不通,因为beta仅包含year1和的估算值year0:const,同时X还包含的列year1:const。换句话说,X包括列两个year0:constyear1:const,这是无法估计这两个系数。

一种解决方法是在将其输入公式之前,先创建“手工”交互项:

tmp$yearXconst <- tmp$year*tmp$const
fe3 <- plm(y ~ year + yearXconst, index=c('ID', 'year'), data=tmp)
summary(fe3)  # works fine

但这很麻烦。除此之外,我可以做些什么来summary.plm使用这种模型?

===

艾莉森,保罗D。2009年。固定效应回归模型。加利福尼亚州洛杉矶:Sage。尤其请参阅第19-21页。


1
plm版本1.6-4 开始,这不再是问题,因为简单地降低了系数系数。
Helix123 '17

Answers:


9

尝试使用

fe3 <- plm(y ~ year * const, index = c('ID', 'year'), data = tmp)

代替。如果您在*交互中多余地包含了固定时间效果,则它甚至可以工作(因为时间已经固定了效果):

fe4 <- plm(y ~ year * const, index = c('ID', 'year'), data = tmp, effect = "twoway")

鉴于*必须使用代替:,有没有办法抑制非相互作用系数的输出?
亚瑟
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.