簡體   English   中英

R plm時間固定效應模型

[英]R plm time fixed effect model

我在固定效果模型上在線找到了這些示例代碼:

代碼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")

有什么區別? 不與國家/地區建立索引是否意味着固定效應模型實際上為年份創建了虛擬變量? 該文檔並沒有很清楚地解釋這一點。

plm ,指定index參數只是格式化數據。 您要查看effect參數,該參數指示是使用單個效果 (您提供的第一個索引), 時間 (第二個)還是雙向 (兩個)效果。 如果您未指定任何內容,則默認為個人

因此,在您的第一個回歸中,您(隱式)使用了personal ,並自己添加了時間效果。 這等效於使用雙向 請參見下面的代碼。

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軟件包 (v0.2.1)創建於2018-11-20

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM