R plm time fixed effect model

可紊 提交于 2019-12-11 06:46:52

问题


I found these sample codes online on fixed effect model:

Code 1

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

Code 2

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

What is the difference? Doesn't index with country,year mean the fixed effect model actually create a dummy variable for year? The documentation does not explain this very clearly.


回答1:


In plm, specifying the index arguments just formats the data. You want to look at the effect argument, which indicates whether to use individual (the first index you provided), time (the second), or twoways (both) effects. If you don't specify anything, individual is the default.

So in your first regression, you (implicitly) used individual, and added time effects yourself. This is equivalent to using twoways. See code below.

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

Created on 2018-11-20 by the reprex package (v0.2.1)



来源:https://stackoverflow.com/questions/28359491/r-plm-time-fixed-effect-model

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!