R2 with plm package
Asked Answered
M

0

6

When estimating the pooled model using the plm package using this syntax I get an R2 that is nearly 0.8.

library(plm)
data <- employmentsez
data$lfirms2 <- data$lfirms*data$lfirms
data$sezname <- as.factor(data$sezname)
data <- plm.data(data, index=c("code", "year"))
fit1 <- plm(lemployment ~ lfirms + lfirms2 + lfirmsfor + lwages +  nuts51 + lgovgrants + leusubs + agrishare, data=data, model="pooling")
    R-Squared:      0.7972
    Adj. R-Squared: 0.79679

With the exact same specification and again with plm but now this syntax I get an R2 that is less than 0.1 and R2 adjusted is negative.

library(plm)
data <- employmentsez
data$lfirms2 <- data$lfirms*data$lfirms
data$sezname <- as.factor(data$sezname)
data <- plm.data(data, index=c("code", "year"))
fit1 <- plm(lemployment ~ lfirms + lfirms2 + lfirmsfor + lwages +  nuts51 + lgovgrants + leusubs + agrishare, data=data, model="within", effect="individual")
summary(fit1)


    R-Squared:      0.085873
    Adj. R-Squared: -0.039652

I think the difference is too big and in Stata you get a higher R2 for the within model using the exact same specifications. Also ought the within model not give a higher R2 when using the exact same specification and adding the fixed effects?

Does anyone know how to fix this problem, is there an alternative way to get the correct R2 with the plm package?

Multilateral answered 21/11, 2017 at 15:9 Comment(3)
It is not the exact same specification as one model is a pooled model and the other is a within model. It is not unambiguous how R2 is defined for within models that is why you see a different value in Stata - search for the terms between R2, within R2 and overall R2.Beitris
Basically as he said, It's not same. One is a individual fixed effect panel data modelling and the other is pooled ols. It's not surprising to see this result.Fledge
I have since found out that with plm we only get R2 for the 'projected' model which means that the variance that is explained by the fixed effect is not included in the R2. But we can get the full R2 inclusive of fixed effects by using the felm package instead. I think it would otherwise be misleading because certainly it is wrong that the pooled model is 'better' than the fixed effect model.Multilateral

© 2022 - 2024 — McMap. All rights reserved.