【问题标题】:How does the plm package handle fixed effects - one dummy for each individual or one less?plm 包如何处理固定效果——每个人一个虚拟对象还是少一个?
【发布时间】:2017-10-27 02:51:59
【问题描述】:

我目前正在尝试使用 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() 包进行固定效应估计时没有出现这个问题,不包括一年和一个单独的假人。 如有任何帮助或建议,我将不胜感激!

【问题讨论】:

    标签: fixed effects lm plm


    【解决方案1】:

    对于您的第三次估计 (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 包中处理此问题:不是通过引入虚拟变量,而是通过对每个个体的数据进行贬义,因为这是等效的(afaik 理论是 Frisch-Waugh-Lovell 定理)。

    【讨论】:

      猜你喜欢
      • 2013-02-18
      • 1970-01-01
      • 2020-03-03
      • 1970-01-01
      • 2017-09-16
      • 2020-10-20
      • 2010-12-30
      • 1970-01-01
      相关资源
      最近更新 更多