【问题标题】:R plm time fixed effect modelR plm 时间固定效应模型
【发布时间】:2015-04-06 05:23:32
【问题描述】:

我在网上找到了这些固定效应模型的示例代码:

代码 1

fixed.time <- plm(y ~ x1 + factor(year), data=Panel, index=c("country", "year"), model="within")

代码 2

fixed.time <- plm(y ~ x1, data=Panel, index=c("country", "year"), model="within")

有什么区别?与国家,年份索引是否意味着固定效应模型实际上为年份创建了一个虚拟变量? 文档没有很清楚地解释这一点。

【问题讨论】:

  • 对不起,我无法编辑,但代码 1 有效果 =“时间”,代码 2 没有效果

标签: r plm


【解决方案1】:

plm 中,指定index 参数只是格式化数据。您想查看effect 参数,它指示是使用individual(您提供的第一个索引)、time(第二个)还是twoways (两者)效果。如果您不指定任何内容,则 individual 是默认值。

所以在您的第一次回归中,您(隐含地)使用了个人,并自己添加了时间效应。这相当于使用twoways。请参阅下面的代码。

library(plm)
#> Loading required package: Formula
Panel <- data.frame(y <-  rnorm(120), x1 = rnorm(120), 
                    country = rep(LETTERS[1:20], each = 6),
                    year = rep(1:6, 20))
## this computes just individual FE
mod2 <- plm(y ~ x1, data=Panel, index=c("country", "year"), model="within")

## this computes individual FE, and you added time FE:
fixed.time <- plm(y ~ x1 + factor(year), data=Panel, index=c("country", "year"), model="within")

## this computes individual and time FE
mod3 <- plm(y ~ x1, data=Panel, index=c("country", "year"), model="within", effect = "twoways")

## second and third model should be identical:
all.equal(coef(fixed.time)["x1"], coef(mod3)["x1"])
#> [1] TRUE

reprex package (v0.2.1) 于 2018 年 11 月 20 日创建

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-24
    • 1970-01-01
    • 2022-01-02
    • 2013-04-04
    • 2017-01-26
    • 2018-11-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多