Cointegration regression diagnostics (Heteroscedasticity and autocorrelation test)

Dear All,
Please I am trying to conduct a regression diagnostics test for my panel cointegration regression models. Specifically I want to check for heteroscedasticity and autocorrelation in my regression residuals (Using FMOLS and DOLS). However I keep getting errors messages.

Below is my codes and error messages. I would appreciate your support

library(plm) 
library(stargazer)
Final_data_c<- pdata.frame(Raw_data_c,index=c("Country","Year"))
attach(Final_data_c)


##################### Regression models

library(cointReg)

DOLS <- cointRegD(ham_exp, ham_rev,   n.lead = 1, n.lag = 1,
                 kmax = "k4", info.crit = "AIC", demeaning = FALSE,
                 check = TRUE, data = Final_data_c)  # Dynmic OLS

FMOLS <- cointRegFM(ham_exp,  ham_rev, demeaning = "false", data = Final_data_c)  # Fully modified OLS



###################  studentized Breusch-Pagan test   for heteroskedasticit
library(lmtest)
bptest(DOLS$residuals)

## Error message =  $ operator is invalid for atomic vectors


####### Autocorrelation test (Breusch–Godfrey Test for Panel Models)
pbgtest(DOLS$residuals)

## Error message = no applicable method for 'pbgtest' applied to an object of class "c('double', 'numeric')"



Below is the datasets

("structure(list(Country = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 8L), .Label = c("CzechRepublic", "Estonia", "Hungary",
"Latvia", "Lithuania", "Poland", "SlovakRepublic", "Slovenia"
), class = "factor"), Year = structure(c(1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
19L, 20L, 21L, 22L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
16L, 17L, 18L, 19L, 20L, 21L, 22L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L,
13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L,
18L, 19L, 20L, 21L, 22L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L,
1L), .Label = c("1998", "1999", "2000", "2001", "2002", "2003",
"2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011",
"2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019"
), class = "factor"), ham_exp = c(40.77598591, 42.46806167, 42.46167976,
42.32561935, 42.32929629, 42.80848971, 42.76903454, 43.33579847,
41.45862483, 42.40266724, 42.27326998, 42.24478127, 42.44815649,
43.02552192, 42.3943724, 42.40041881, 42.72471971, 42.17953612,
42.42813178, 42.31616525, 42.04044862, 42.25521988, 37.89123874,
37.64027451, 37.84763634, 37.99463027, 37.60662669, 37.39252184,
37.46564496, 37.38932771, 37.27510814, 37.22490779, 37.18912498,
37.21607256, 37.82824471, 38.59027311, 38.09874335, 37.68990227,
37.83860188, 37.78739471, 37.70444381, 37.87742255, 37.93343263,
37.92342644, 50.1557514, 49.2472858, 49.17547738, 49.13849996,
48.61112771, 48.3139609, 48.80366431, 49.18493771, 48.82254094,
48.85890821, 49.23633247, 49.36885211, 48.96398728, 49.02426083,
49.14298794, 48.91222162, 48.93891535, 49.04923387, 49.19907165,
49.26554986, 48.86363847, 48.24979425, 37.50713175, 37.45523669,
38.50306125, 38.63158684, 36.56326589, 36.8137813, 37.63475615,
37.01901347, 37.8522304, 37.36110579, 38.11966667, 36.92585807,
38.71673367, 39.90725115, 38.25641265, 36.3239621, 36.96129909,
37.59899111, 37.75708631, 37.65596303, 37.30102795, 38.00757865,
37.2328368, 43.25505525, 35.52251685, 37.63610017, 37.03055482,
36.23902372, 35.91916304, 35.66884007, 36.30713947, 36.16148981,
36.2650684, 36.673331, 37.83352712, 40.35183292, 37.39357436,
38.10805341, 35.0013435, 36.2995691, 36.07809282, 36.46610422,
35.92389617, 35.67288697, 45.9395045, 44.00473243, 43.70559638,
43.34130147, 42.87109069, 44.02000932, 43.91859039, 44.00844091,
43.18558444, 43.63574856, 43.64050092, 43.0739205, 43.62936295,
43.80565767, 44.07172579, 43.28717105, 43.11796317, 43.12681613,
43.08222597, 42.84685984, 42.71667021, 42.8145267, 46.07785543,
45.63039427, 44.07559478, 44.18541726, 45.87251546, 44.60266494,
43.39538804, 42.01199319, 40.48397924, 40.57458113, 40.62451608,
39.79615353, 39.55899787, 41.71928948, 42.34485439, 41.76553533,
41.50637393, 41.79304026, 42.291355, 43.14340443, 42.70389088,
41.86520509, 45.78240658), ham_rev = c(39.40013666, 39.56562783,
39.17461297, 39.42667523, 38.96432458, 39.19979708, 39.51097927,
41.22521413, 39.86721827, 39.6600092, 39.67238215, 39.92760768,
39.43198558, 39.53874875, 39.81674815, 40.19754491, 40.20120042,
40.54112549, 40.01398715, 40.42684339, 39.98503217, 40.16474412,
38.2086722, 38.09041216, 37.99680757, 37.64169656, 37.41567296,
37.15736696, 37.28765012, 37.48235246, 37.44735715, 37.10997649,
37.27818323, 37.42913988, 37.49252851, 38.79998833, 38.6967504,
38.05299242, 37.99452417, 37.97270356, 37.92454761, 38.14005286,
38.14893741, 38.0396887, 45.38071815, 43.76411969, 43.84358779,
44.21413202, 44.50570743, 43.72080148, 43.2366862, 43.30060159,
43.51914227, 43.12599615, 43.52036863, 45.15750925, 44.73913985,
45.29522223, 44.36684131, 44.17892412, 46.17212272, 45.94663671,
45.76903332, 46.52792587, 44.24536286, 44.33340452, 35.77247752,
36.70386037, 37.25162034, 35.76391243, 33.86903671, 33.68786816,
34.46843174, 33.84290453, 35.63749849, 34.91156215, 36.36863776,
33.83198975, 34.73253168, 35.98008849, 36.85713677, 35.45425072,
36.28637655, 35.86348134, 35.95841977, 35.9832732, 36.24501281,
36.58657611, 34.74682091, 38.03032551, 34.44733356, 34.62312114,
33.51001765, 32.81744493, 34.38478332, 33.91749703, 34.78754386,
35.21754383, 34.74875746, 34.85123184, 35.01036667, 35.10208685,
34.37283095, 33.34774052, 34.16048559, 34.45671806, 35.32158449,
35.05742502, 34.30953512, 34.05683745, 41.06982713, 40.84224792,
40.21196709, 40.08259471, 39.82600652, 39.69335246, 39.83114817,
39.77365558, 39.55726237, 39.6430936, 39.8793838, 39.95681237,
39.9012855, 39.51331528, 39.3345007, 39.48332912, 39.55402523,
39.48403258, 39.4544671, 39.52312956, 39.51621985, 39.60314757,
41.14453549, 40.60544034, 39.15260607, 39.86992157, 39.2139927,
37.51567243, 37.27684096, 37.53391565, 36.02053292, 37.59162829,
35.79751791, 35.39308141, 35.76225474, 37.35165575, 35.50322675,
37.94165368, 36.99597252, 39.66252343, 39.61078336, 42.05249876,
38.67228303, 39.74640741, 44.1873312)), row.names = c("CzechRepublic-1998",
"CzechRepublic-1999", "CzechRepublic-2000", "CzechRepublic-2001",
"CzechRepublic-2002", "CzechRepublic-2003", "CzechRepublic-2004",
"CzechRepublic-2005", "CzechRepublic-2006", "CzechRepublic-2007",
"CzechRepublic-2008", "CzechRepublic-2009", "CzechRepublic-2010",
"CzechRepublic-2011", "CzechRepublic-2012", "CzechRepublic-2013",
"CzechRepublic-2014", "CzechRepublic-2015", "CzechRepublic-2016",
"CzechRepublic-2017", "CzechRepublic-2018", "CzechRepublic-2019",
"Estonia-1998", "Estonia-1999", "Estonia-2000", "Estonia-2001",
"Estonia-2002", "Estonia-2003", "Estonia-2004", "Estonia-2005",
"Estonia-2006", "Estonia-2007", "Estonia-2008", "Estonia-2009",
"Estonia-2010", "Estonia-2011", "Estonia-2012", "Estonia-2013",
"Estonia-2014", "Estonia-2015", "Estonia-2016", "Estonia-2017",
"Estonia-2018", "Estonia-2019", "Hungary-1998", "Hungary-1999",
"Hungary-2000", "Hungary-2001", "Hungary-2002", "Hungary-2003",
"Hungary-2004", "Hungary-2005", "Hungary-2006", "Hungary-2007",
"Hungary-2008", "Hungary-2009", "Hungary-2010", "Hungary-2011",
"Hungary-2012", "Hungary-2013", "Hungary-2014", "Hungary-2015",
"Hungary-2016", "Hungary-2017", "Hungary-2018", "Hungary-2019",
"Latvia-1998", "Latvia-1999", "Latvia-2000", "Latvia-2001", "Latvia-2002",
"Latvia-2003", "Latvia-2004", "Latvia-2005", "Latvia-2006", "Latvia-2007",
"Latvia-2008", "Latvia-2009", "Latvia-2010", "Latvia-2011", "Latvia-2012",
"Latvia-2013", "Latvia-2014", "Latvia-2015", "Latvia-2016", "Latvia-2017",
"Latvia-2018", "Latvia-2019", "Lithuania-1998", "Lithuania-1999",
"Lithuania-2000", "Lithuania-2001", "Lithuania-2002", "Lithuania-2003",
"Lithuania-2004", "Lithuania-2005", "Lithuania-2006", "Lithuania-2007",
"Lithuania-2008", "Lithuania-2009", "Lithuania-2010", "Lithuania-2011",
"Lithuania-2012", "Lithuania-2013", "Lithuania-2014", "Lithuania-2015",
"Lithuania-2016", "Lithuania-2017", "Lithuania-2018", "Lithuania-2019",
"Poland-1998", "Poland-1999", "Poland-2000", "Poland-2001", "Poland-2002",
"Poland-2003", "Poland-2004", "Poland-2005", "Poland-2006", "Poland-2007",
"Poland-2008", "Poland-2009", "Poland-2010", "Poland-2011", "Poland-2012",
"Poland-2013", "Poland-2014", "Poland-2015", "Poland-2016", "Poland-2017",
"Poland-2018", "Poland-2019", "SlovakRepublic-1998", "SlovakRepublic-1999",
"SlovakRepublic-2000", "SlovakRepublic-2001", "SlovakRepublic-2002",
"SlovakRepublic-2003", "SlovakRepublic-2004", "SlovakRepublic-2005",
"SlovakRepublic-2006", "SlovakRepublic-2007", "SlovakRepublic-2008",
"SlovakRepublic-2009", "SlovakRepublic-2010", "SlovakRepublic-2011",
"SlovakRepublic-2012", "SlovakRepublic-2013", "SlovakRepublic-2014",
"SlovakRepublic-2015", "SlovakRepublic-2016", "SlovakRepublic-2017",
"SlovakRepublic-2018", "SlovakRepublic-2019", "Slovenia-1998"
), class = c("pdata.frame", "data.frame"), index = structure(list(
Country = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L), .Label = c("CzechRepublic",
"Estonia", "Hungary", "Latvia", "Lithuania", "Poland", "SlovakRepublic",
"Slovenia"), class = "factor"), Year = structure(c(1L, 2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
16L, 17L, 18L, 19L, 20L, 21L, 22L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
19L, 20L, 21L, 22L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
19L, 20L, 21L, 22L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 1L), .Label = c("1998",
"1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006",
"2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014",
"2015", "2016", "2017", "2018", "2019"), class = "factor")), class = c("pindex",
"data.frame"), row.names = c(NA, 155L))) ")

Hi @Benny.owusuk,

This is a great community and people are eager to help you. However, they need all the tools they can get to be able to do so. You have provided your code and that's perfect. But without the data, they cannot run it on their own computer to check what is not working.

Also, please consider copying and pasting your code in code blocks. You can do this by placing your pointer on a new line and pressing Ctrl + Shift + C. This will create a code block in which you can paste your code.

Instead of creating a new question, you can just edit your current question so that it incorporates the tips I have given you.

:slight_smile:

Just for the sake of formatting (for future people who will look at your post), will you please also include the dataset in a code block? Thank you

:slight_smile:

Thank you for the notification.

I wish I had read your question more thoroughly before suggesting that you reformat your code (even though I believe it is important if you are seeking for help).

The dynamic OLS and fully-modified OLS models are used when you have already determined that the variables in your model are cointegrated. In other words, they share a long-run equilibrium relationship. The regression diagnostics that you are trying to run a more suited for traditional OLS models. To my knowledge (and I may be wrong), you do not test for heteroskedasticity on the residuals of the DOLS and FOMLS models. I encourage you to look into by looking through the original papers.

On the R side of things, the bptest takes as an input a model formula. In your code, you try to give it your residuals, so it produces an error. Here is a minimal example:

# Does the weight of cars affect their fuel efficiency?
mod <- lm(mpg ~ wt, data = mtcars)
summary(mod) # It appear that the answer to the question is yes!

Call:
lm(formula = mpg ~ wt, data = mtcars)

Residuals:
    Min      1Q  Median      3Q     Max 
-4.5432 -2.3647 -0.1252  1.4096  6.8727 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  37.2851     1.8776  19.858  < 2e-16 ***
wt           -5.3445     0.5591  -9.559 1.29e-10 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 3.046 on 30 degrees of freedom
Multiple R-squared:  0.7528,	Adjusted R-squared:  0.7446 
F-statistic: 91.38 on 1 and 30 DF,  p-value: 1.294e-10

# Test for heteroskedasticity
library(lmtest)
bptest(mpg ~ wt, data = mtcars)

	studentized Breusch-Pagan test

data:  mpg ~ wt
BP = 0.040438, df = 1, p-value = 0.8406

Dear @gueyenono, thank you for the feedback. Honestly I have not see these test done in any of the literature I read so far. The only thing I have see so far is the calculation of bootstrap critical values or confidence intervals which should be robost against cross sectional dependence in the panel model. However I believe it will be good to show that the cointegration regression model do not suffer from heteroscedasticity, serial correlation or even cross sectional dependence. Otherwise please do you know about how to do any diagnostic test on the cointegration regression model?

Be careful to not treat time series models the same way as traditional regression models. A cointegration regression is a time series model. The estimated coefficients are not interpreted the same way as, say, the estimates of an ordinary least squares model. It seems to me (again, I may be wrong) that you consider all regressions to be the same. Your current work is in the realm of time series models and, as such, you should use the tests are that more suited to this type of exercise. For example, the problem of serial correlation, is almost always present in time series models. However, you cannot discard their results because of that because they attempt to answer different questions than least squares models. I know I am being vague, but I hope you get the point.

Regarding your question, honestly, when I used these models in research, I only used the reported p-values to determine whether the variables had a significant long-run relationship or not.

Dear @gueyenono, Thank you once again for your feedback.
Actually, my data is panel and not time series. I noticed the cointegration regression in R is for time series. However when I estimated the panel cointegration regression (FMOLS and DOLS) in other programs (Specifically Eviews), I derived the same results as the estimation in R. Thanks for your comments

Panels combine both cross-sectional and time-series dimensions and are generally treated using time series models. You will notice that you have a Year variable in your own dataset.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

Thank you sir. I have edited the information. I would appreciate your support