【问题标题】:Fixed effects regression with plm使用 plm 进行固定效应回归
【发布时间】:2020-06-30 12:01:23
【问题描述】:

下面的代码使用 biglm 运行时间序列回归“excessr ~ mkt_rf”,因为函数 lm 不适用于我的真实数据集。

现在我想从 biglm 切换到 plm 以解决固定效果。不幸的是 plm 不起作用。

有谁知道我可以改变 plm 的工作吗?提前致谢!

library(biglm)
library(plm)
library(data.table)

union_with_factors = data.table(
  t = c(1,2,3,4,5,1,2,3,4,5,1,2,3,4,5),
  excessr  = c(10,23,13,53,43,76,34,12,45,13,42,31,4,53,64),
  FundId = c("x","x","x","x","x","y","y","y","y","y","z","z","z","z","z"),
  mkt_rf = c(1,1,2,1,3,1,1,2,1,3,1,1,2,1,3)
)

sp <- split(union_with_factors, union_with_factors$FundId)
beta <- sapply(sp, function(tmp){
  fit <- plm(excessr ~ mkt_rf, data = tmp)
  coef(fit)
})

【问题讨论】:

  • 应该包含固定效果的列是什么? FundId?
  • 我对统计数据不是很深入,但我的数据集不平衡,因此我需要应用 plm 以避免在回归中出现资金固定效应

标签: r regression


【解决方案1】:

假设个人的 ID 由 FundId 给出,时间 ID 由 t 给出,以下是如何应用固定效应回归:

library(biglm)
library(data.table)
library(plm)

union_with_factors = data.table(
  t = c(1,2,3,4,5,1,2,3,4,5,1,2,3,4,5),
  excessr  = c(10,23,13,53,43,76,34,12,45,13,42,31,4,53,64),
  FundId = c("x","x","x","x","x","y","y","y","y","y","z","z","z","z","z"),
  mkt_rf = c(1,1,2,1,3,1,1,2,1,3,1,1,2,1,3)
)
fit <- plm(excessr ~ mkt_rf, 
             data = union_with_factors, 
             index = c("FundId", "t"), 
             model = "within")
summary(fit)
fixef(fit)

有关详细信息,请参阅hereplm 文档(控制台中的?plm

编辑:this postthis article 之后,您似乎可以使用pmg(也在plm 包中)进行Fama-MacBeth 回归:

fama_macbeth <- pmg(excessr ~ mkt_rf, 
                   data = union_with_factors, 
                   index = c("FundId", "t"))
summary(fama_macbeth)

【讨论】:

  • 谢谢你,这行得通。我只是想知道,因为我应该使用 Fama McBeth 回归,我首先对每个 FundId 的时间序列(excessr ~ mkt_rf)进行回归。然后在第二步中,回归我在每个 t 的横截面(excessr ~ Beta_mkt_rf)之前计算的系数。鉴于此过程,是否可以使用 plm 功能?在我看来 plm 将这两个步骤一起完成..
  • 我从来没有这样做过,但似乎你可以用pmg 做到这一点。有关详细信息,请参阅我的编辑
  • 虽然 plm 可以很好地处理我的数据,但 pmg 会抛出一个错误,上面写着“index = c("FundId", : Insufficient number of time period"。你知道如何解决这个问题吗。非常感谢为你的努力!!
  • 我从未使用过这种类型的回归,但错误消息非常明确,我无法帮助您处理数据。我的回答对你的例子有用吗?
猜你喜欢
  • 2020-04-27
  • 1970-01-01
  • 2023-04-04
  • 2020-03-20
  • 2017-04-24
  • 1970-01-01
  • 1970-01-01
  • 2015-04-06
  • 2021-06-16
相关资源
最近更新 更多