Weights with plm package
Asked Answered
F

2

9

My data frame looks like something as follows:

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)

I would like to run the following weighted regression:

plm(y~x + factor(my.times) , 
data=play.data, 
index=c('groups','my.times'), model='within', weights= POP)

But I do not believe the plm package allows for weights. The answer I'm looking for the coefficient from the model below:

fit.regular<- lm(y~x + factor(my.times) + factor(my.groups),
weights= POP, data= play.data)
desired.answer<- coefficients(fit.regular)

However, I am looking for an answer with the plm package because it is much faster to get the coefficient of the within estimator with plm with larger datasets and many groups.

Foxtail answered 13/4, 2015 at 6:8 Comment(1)
The development version of plm now features a weights argument for plm().Eberto
P
3

Edit: This problem does not exist anymore since plm features a weight function now (see @Helix123 comment above).

Even though I know of no solution with the plm package, the felmfunction in the lfe package handles weights correctly in the context of fixed effects (which seems what you need from the syntax of your example code). It is particularly written with a focus on speed in the presence of many observations and groups.

The lfe package focuses on fixed effects only, so if you need random effects the lme4 package might be more suited to your needs.

Purpose answered 8/12, 2016 at 13:5 Comment(2)
The plm() weights option seems to be bugged, though.Typewrite
@Typewrite Could you please be more specific? Thanks.Relation
C
1

I am looking for exactly this information. I found this answer http://r.789695.n4.nabble.com/Longitudinal-Weights-in-PLM-package-td3298823.html by one of the author of the packages, which seems to suggest there is no way of using weights directly within the plm package.

Carricarriage answered 18/2, 2017 at 1:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.