下面的代码使用biglm运行时间序列回归"excessr ~ mkt_rf“,因为lm函数不适用于我的真实数据集。
现在,我想要从大到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)
})发布于 2020-03-19 11:08:09
假设个人的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)有关详细信息,请参阅这里和plm文档(控制台中的?plm)
编辑:在这个职位和这篇文章之后的,您似乎可以使用pmg (也在plm包中)进行Fama-MacBeth回归:
fama_macbeth <- pmg(excessr ~ mkt_rf,
data = union_with_factors,
index = c("FundId", "t"))
summary(fama_macbeth)https://stackoverflow.com/questions/60755701
复制相似问题