I want to test a fixed effects regression for heteroscedasticity with lmtest::bptest
. The test results I get from bptest
are identical for a fixed effects regression and OLS.
It seems as if bptest
automatically extracts the formula
from the input object and runs an OLS with those variables, regardless of the regression model of the input. From the ?bptest
:
The Breusch-Pagan test fits a linear regression model to the residuals of a linear regression model (by default the same explanatory variables are taken as in the main regression model) and rejects if too much of the variance is explained by the additional explanatory variables.
No error or warning is produced to tell you that the output of the function is not based on the model you used as input.
Question
First of all, is there a way to test my plm-object for heteroscedasticity with pbtest
? Since I am assuming there's not, is there a way to run a Breusch Pagan test for a fixed effects regression?
Here is a reproducible example:
# load the data:
df <- structure(list(country = c(1, 1, 2, 2, 3, 3, 4, 4, 5, 5), year = c(2010,
2015, 2010, 2015, 2010, 2015, 2010, 2015, 2010, 2015), dv1 = c(28.61,
31.13, 38.87, 39.46, 68.42, 70.39, 79.36, 80.55, 70.14, 71.48
), iv1 = c(-20.68, 0, NA, NA, -19.41, -18.73, 24.98, 25.23, 21.23,
-21.06), iv2 = c(-4.23, NA, NA, NA, -4.92, -4.22, 9.19, 9.37,
4.15, -3.92)), .Names = c("country", "year", "dv1", "iv1", "iv2"
), row.names = c(2L, 3L, 5L, 6L, 8L, 9L, 11L, 12L, 14L, 15L),class
="data.frame")
library(plm)
library(lmtest)
# Run the fixed effects regression
FEoutput <- plm(dv1 ~ iv1 + iv2, data = df,
model = "within", index = c("country", "year"))
bptest(FEoutput)
# studentized Breusch-Pagan test
#
# data: FEoutput
# BP = 1.9052, df = 2, p-value = 0.3857
# Run the OLS regression
OLSoutput <- lm(dv1 ~ iv1 + iv2, data = df)
bptest(OLSoutput)
# studentized Breusch-Pagan test
#
# data: OLSoutput
# BP = 1.9052, df = 2, p-value = 0.3857
Including country dummies into the OLS regression to create a fixed effects regression also didn't work, because the country dummies increase the degrees of freedom of the test:
OLSctry <- lm(dv1 ~ iv1 + iv2 + factor(country), data = df)
bptest(OLSctry)
# studentized Breusch-Pagan test
#
# data: OLSctry
# BP = 7, df = 5, p-value = 0.2206
Thanks in advance!