PLM 软件包如何处理每个人固定一个假人或少一个假人?



我目前正在尝试习惯 plm 包,并尝试使用 plm() 函数和 lm() 函数制作具有单个效果的固定效果(只是为了这样做,请忽略错误的规范)。我发现只有当我在 lm() 回归中为每个单独的 N 包含一个虚拟变量时,我才能复制 plm() 回归的结果。据我所知,回归中应该始终包含 N-1 个虚拟变量。有谁知道 plm 如何处理各个固定效果?顺便说一句,时间固定效果也是如此。

这是我使用Grunwald 1958的示例数据的代码(也包含在plm包中),请原谅相当笨拙的虚拟变量创建:

################################################################################
## Fixed Effects Estimation with plm() and lm() with individual effects
################################################################################
# Prepare R sheet
library(plm)
library(dplyr)
################################################################################
# Get data
data<-read.csv("http://people.stern.nyu.edu/wgreene/Econometrics/grunfeld.csv")
class(data)
data.tbl<-as.tbl(data)
#I = Investment
#F = Real Value of the Firm
#C = Real Value of the Firm's Capital Stock
################################################################################
# create firm (individual) dummies
firmdum<-rbind(matrix(rep(c(1,0,0,0,0,0,0,0,0,0),20),ncol = 10,byrow = T),
matrix(rep(c(0,1,0,0,0,0,0,0,0,0),20),ncol = 10,byrow = T),
matrix(rep(c(0,0,1,0,0,0,0,0,0,0),20),ncol = 10,byrow = T),
matrix(rep(c(0,0,0,1,0,0,0,0,0,0),20),ncol = 10,byrow = T),
matrix(rep(c(0,0,0,0,1,0,0,0,0,0),20),ncol = 10,byrow = T),
matrix(rep(c(0,0,0,0,0,1,0,0,0,0),20),ncol = 10,byrow = T),
matrix(rep(c(0,0,0,0,0,0,1,0,0,0),20),ncol = 10,byrow = T),
matrix(rep(c(0,0,0,0,0,0,0,1,0,0),20),ncol = 10,byrow = T),
matrix(rep(c(0,0,0,0,0,0,0,0,1,0),20),ncol = 10,byrow = T),
matrix(rep(c(0,0,0,0,0,0,0,0,0,1),20),ncol = 10,byrow = T)
)
colnames(firmdum)<-paste("firm",c(1:10),sep = "")
firmdum.tbl<-tbl_df(firmdum)
firmdum.tbl<-sapply(firmdum.tbl, as.integer)
###############################################################################################
# Estimation with individual fixed effects (plm)
dataset<-tbl_df(cbind(data.tbl,firmdum.tbl))
est1<- plm(I ~ F + C, data = dataset, model = "within", effect = "individual")
summary(est1)
plot(residuals(est1))
# Replication with lm
individualeffects<-tbl_df(cbind(data.tbl,firmdum.tbl))
est2<-lm(I ~ . -1 -FIRM -YEAR, individualeffects)
summary(est2)
plot(residuals(est2))
# Now exclude 1 dummy (as should be done in fixed effects)
individualeffects<-tbl_df(cbind(data.tbl,firmdum.tbl))
est3<-lm(I ~ . -1 -FIRM -YEAR -firm1, individualeffects)
summary(est3)
plot(residuals(est3))

差异很小,但了解 plm 功能如何处理固定效果会很有趣。在模型上运行测试时,我遇到了一个问题,当我使用 lm() 包进行固定效应估计时,不包括一年和一个单独的虚拟人时,这个问题并没有出现。 我将不胜感激任何帮助或建议!

对于您的第 3 个估计 (est3),排除一个假人和排除截距会给你不同的结果。当模型中存在截距时,排除一个虚拟(取 n-1 个假人)的做法是有意义的,因为变量变得线性相关(如果将所有虚拟列相加,您将获得所有 1 的列,即截距)。如果没有截距,您希望模型中的所有假人:

est4 <- lm(I ~ . -1 -FIRM -YEAR, individualeffects)
summary(est4)

这(est4)给出了与plm()方法相同的估计。

顺便说一句:通过使用一个因素,更容易为您创建假人:

est5 <- lm(I ~ F + C + factor(FIRM), data = individualeffects)
summary(est5)
[...]
Coefficients:
Estimate Std. Error t value Pr(>|t|)    
(Intercept)     -70.29672   49.70796  -1.414    0.159    
F                 0.11012    0.01186   9.288  < 2e-16 ***
C                 0.31007    0.01735  17.867  < 2e-16 ***
factor(FIRM)2   172.20253   31.16126   5.526 1.08e-07 ***
factor(FIRM)3  -165.27512   31.77556  -5.201 5.14e-07 ***
factor(FIRM)4    42.48742   43.90988   0.968    0.334    
factor(FIRM)5   -44.32010   50.49226  -0.878    0.381    
factor(FIRM)6    47.13542   46.81068   1.007    0.315    
factor(FIRM)7     3.74324   50.56493   0.074    0.941    
factor(FIRM)8    12.75106   44.05263   0.289    0.773    
factor(FIRM)9   -16.92555   48.45327  -0.349    0.727    
factor(FIRM)10   63.72887   50.33023   1.266    0.207    
[...]

注意:没有factor(FIRM)1

你要求的回复就这么多。您还询问了如何在plm包中处理此问题:不是通过引入虚拟变量,而是通过贬低每个人的数据,因为这是等价的(该理论是弗里施-沃-洛弗尔定理)。

最新更新