我的数据框如下所示:

unique.groups<- letters[1:5]
unique_timez<- 1:20
groups<- rep(unique.groups, each=20)
my.times<-rep(unique_timez, 5)

play.data<- data.frame(groups, my.times, y= rnorm(100), x=rnorm(100), POP= 1:100)

我想运行以下加权回归:
plm(y~x + factor(my.times) ,
data=play.data,
index=c('groups','my.times'), model='within', weights= POP)

但是我不认为plm软件包可以承受重量。我正在从下面的模型中寻找系数的答案:
fit.regular<- lm(y~x + factor(my.times) + factor(my.groups),
weights= POP, data= play.data)
desired.answer<- coefficients(fit.regular)

但是,我正在寻找plm软件包的答案,因为使用plm来获取较大数据集和许多组的估计器的系数要快得多。

最佳答案

编辑:由于plm现在具有权重功能(请参见上面的@ Helix123注释),因此不再存在此问题。

即使我不知道plm包没有解决方案,但 felm 包中的lfe函数可以在固定效果的上下文中正确处理权重(这似乎是示例代码语法所需要的)。特别是在存在许多观察和小组的情况下,着眼于速度。
lfe包仅关注固定效果,因此,如果您需要随机效果,则lme4包可能会根据您的需要be more suited

10-08 18:32