3
$\begingroup$

I have a panel data containing 12 different years, many id:s per year (some id:s missing in some years..unbalanced panel) and many variables. I'd like to test for auto correlation and I have run some regression models in OLS containing "year" variable to control for time. I have checked auto correlation by using lmtest::bgtest and it suggests no auto correlation (my data is in yearly order..2002,2002,2002,2003,2003....). I learned that the plm-package has function pbgtest which should be the same as bgtest but when I run the exact same OLS model in plm and test for auto correlation, the test suggests autocorrelation. Im using model = "pooling" in my plm function, so it should be exactly the same as my OLS model created by the lm-function. I'd like to know which one of the test to use/trust and why do the results differ?

example of my model:

a <- plm(y~x,model="pooling")
b <- lm(y~x)
plm::pbgtest(a)
lmtest::bgtest(b)

Test results are not the same although data is the same and summary for a and b are same. The difference is not due to different order or type= "F" or "Chisq".

$\endgroup$
2
$\begingroup$

The argument order has different default values when you use pbgtest() compared to bgtest().

For pbgtest() order = NULL, for bgtest() order = 1. See also the section Note in the documentation (?pbgtest).

What you want for a panel model the answer from pbgtest() (no matter what you want order to be).

However, you will not get the same numbers for both functions if you apply it to a panel model (fixed or random effects). This has a rather technical reason: lmtest::bgtest takes the data from model_object$model which are the original (untransformed) data in any case. For panel models, the test needs to be run on the (quasi-)demeaned data and pbgtest() being a wrapper around lmtest::bgtest() does excatly that: extract the (quasi-)demeaned data and pass them on to lmtest::bgtest(). For a pooling model, you will get the same numbers as the data are not transformed.

Please also note that the data in models estimated by plm might be in a different order as plm re-orders the data to be a stacked time series. To check that, one can compare the data and its order used in estimation by looking at plm_object$model and lm_object$model. A different order of observations will lead to differnt results of pbgtest and bgtest even for pooling models.

Here is a code example how pbgtest() works in principle:

library(plm)
data("Grunfeld", package = "plm")
g_re <- plm(inv ~ value + capital, data = Grunfeld, model = "random")

# extract (quasi-)demeanded data:
X <- model.matrix(g_re)
y <- pmodel.response(g_re)
# make a lm model object to be passed on to lmtest::bgtest()
lm.mod <- lm(y ~ X - 1)

# same coefficients:
all.equal(lm.mod$coefficients, g_re$coefficients, check.attributes = FALSE)
lmtest::bgtest(lm.mod, order = 1)
plm::pbgtest(g_re, order = 1) # identical results
$\endgroup$
  • 1
    $\begingroup$ Thanks for your response. I have tried same orders but they dont match. Bgtest implies no autocorrelation while pbgtest implies autocorrelation. $\endgroup$ – user6574498 Jun 29 '17 at 20:44
  • 1
    $\begingroup$ When you estimate a model with plm, your data is re-ordered if not already in the order plm uses. If you estimate with lm, no re-odering is performed, the model estimates will be the same, tough. However, what is forwared by pbgtest to bgtest is then in a different order compared to applying bgtest directly to your lm object. Maybe that is the reason? $\endgroup$ – Helix123 Jul 1 '17 at 20:44
  • 1
    $\begingroup$ You can check the ordering by looking at plm_object$model and lm_object$model. $\endgroup$ – Helix123 Jul 1 '17 at 20:52
  • $\begingroup$ Please also check, the argument for plm your are looking for is model = "pooling", not type = "pooling", you can check that you estimated a pooling model by summary(plm_object) and looking at its first rows. $\endgroup$ – Helix123 Jul 1 '17 at 21:01
  • $\begingroup$ Hey, thanks that ordering solves the problem. In plm the data gets in correct order i.e the function recognizes panel structure of the data correctly while in bgtest i didnt have the panel structure. In bgtest i just told the function that observations are in timely order but they werent due the panel structure. $\endgroup$ – user6574498 Jul 2 '17 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.