Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weights with plm package

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.

like image 923
Zslice Avatar asked Apr 13 '15 06:04

Zslice


People also ask

What is a PLM package?

plm package: linear models for panel data. Description. plm is a package for R which intends to make the estimation of linear panel models straightforward. plm provides functions to estimate a wide variety of models and to make (robust) inference.


Video Answer


1 Answers

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.

like image 78
Felix Avatar answered Oct 01 '22 09:10

Felix