ycroissant / plm

Panel Data Econometrics with R
GNU General Public License v2.0
50 stars 13 forks source link

Problems with 'weight' argument when using 'within' estimator #5

Open jesus-prieto opened 3 years ago

jesus-prieto commented 3 years ago

Consider an example from the help:

> set.seed(10)
> w=runif(200)
> w=(w)^-6
> grun.fe_w <- plm(inv~value+capital-1, data = Grunfeld, model = "within", weights = w)
> grun.fe_lm_w <- lm(inv~value+capital+factor(firm)-1, data = Grunfeld, weights = w)
> rbind(coefficients(grun.fe_w),coefficients(grun.fe_lm_w)[1:2])
           value     capital
[1,] -0.02815926 0.002911782
[2,] -0.02697912 0.093432287

As far as I'm concern, coeficcients should be equal, as the estimator used to compute them is the same. Fixed effects differ too:

> rbind(fixef(grun.fe_w),coefficients(grun.fe_lm_w)[3:12])

            1        2        3         4        5        6        7        8        9       10
[1,] 728.1698 465.1416 155.7911 105.29074 66.90317 66.93043 50.89642 61.53446 50.41692 5.064283
[2,] 755.1351 463.0828 141.8153  57.60098 19.10493 30.22032 20.47606 54.01505 29.12005 4.797652

In addition, residuals method provides strange results.

> summary(as.numeric(residuals(grun.fe_w)))

      Min.    1st Qu.     Median       Mean    3rd Qu.       Max. 
-2127699.0     -493.3      -13.6    -5014.3      110.9  1659085.3 

If we fit the model by ourselves, we obtein something which seems to be ok.

> y_hat_plm <- Grunfeld$value*coefficients(grun.fe_w)[1] + Grunfeld$capital*coefficients(grun.fe_w)[2] + 
> as.numeric(fixef(grun.fe_w)[Grunfeld$firm])
> plot(y_hat_plm, Grunfeld$inv, cex=w*1e-8)
> abline(0, 1, col = 'red', lty = 'dashed', lwd = 2)

issueplm

But compared with the model obtain with lm, the results seem to be worse.

> plot(as.numeric(fitted(grun.fe_lm_w)), Grunfeld$inv, cex=w*1e-8)
> abline(0, 1, col = 'red', lty = 'dashed', lwd = 2)

issueplm2

tappek commented 3 years ago

Thank you for reporting. Seems like there is something fishy here. As far as I remember, the weights implementation is not fully-fledged yet and does not yet support weighted residuals.

Note to the dev team: