Long Run Linkages: A Briefer on the Johansen Cointegration Methodology | by Justin Eloriaga | Towards Data Science

In Economics, there are numerous variables that may appear non-stationary on the outset but when a linear combination of these non-stationary series is made, the linear combination may be described as stationary. While most economists think that Cointegration is some deep theoretical construct, the definition is actually the first sentence of this article. Theoretically, it need not be motivated by any form of theory. However, economists believe that some underlying long run trend or steady state may be pulling on these variables to comove together. Just like a man walking his dog on the park with a leash tied to its neck, they will always move together even if the dog gets distracted by the big flower on the lefthand side of the bench or another dog barking in the corner.
In the world of econometrics, the most popular methodology is based on Soren Johansen’s cointegration test.
Johansen’s methodology is based on the idea that estimating the rank of gives us information about pi whether there is cointegration and the number of these cointegrating relationships. By definition, the rank of pi is the maximum number of independent vectors within this matrix. If we have three endogenous variables, we can only have three independent vectors and no more than that. The rank could be zero or at most three or anywhere in that range. That is, the rank cannot exceed the number of endogenous variables in the system.
If the rank of pi is equal to zero, then it is said that there is no cointegration. This implies that pi = 0 and you can see this in the equation. If you substituted that in the equation, then all the error correction terms would disappear, hence the system collapses to a simple VAR in differences. If the rank of is equal to the number of endogenous variables which we refer to as a full rank, then it suggests that all variables are I(0) or the variables are all stationary. So in that case, we cannot talk about cointegration between non-stationary variables as the variables are already stationary. Hence, you can just run a VAR in levels. If the rank of is strictly between zero and the number of endogenous variables, 0 < rank(pi) < n or less than a full rank, then there are r number of independent cointegrating relationships where r = rank(pi)
There are two types of tests in the Johansen methodology. The first is the trace statistic for each rank r . In the case of our model with three endogenous variables, r being 0, 1, or 2. The null hypothesis of this statistic is that the rank is at most r versus the alternative hypothesis that the rank is strictly greater than this r . The second is the maximum eigenvalue statistic for each rank r . The null hypothesis is that the rank is equal to rank(pi) versus the alternative hypothesis is that the rank is rank(pi) + 1.
The time has come to provide an actual example testing for cointegration in R. To do this, we need to use the “urca” package which contains the ca.jo command to implement the test. To start of, we load the packages required and load the dataset “VECM_LectureNotes.csv using the read_csv() command. The dataset and code can be found here: https://drive.google.com/drive/folders/1QHUwS83GAUOVnxnoi-OZ6-shmTwo8mdB?usp=sharing
library(urca)library(forecast)library(tidyverse)data <- read_csv(file.choose())head(data)
We then declare our time series variables using the ts() command. We note that the series starts in Q1 of 2001 until Q1 of 2020. This is obviously quarterly data so we set the frequency to four.
GDP <- ts(data$lnGDP, start = c(2003,1,31), frequency = 4)CPI <- ts(data$lnCPI, start = c(2003,1,31), frequency = 4)M3 <- ts(data$lnM3, start = c(2003,1,31), frequency = 4)
After declaring the series as a ts object, we will then need to bind the variable into a singular system.To do this, we use the cbind() command. We store the said system into an object, in this case dset
dset <- cbind(GDP,CPI,M3)
After which, we would need to select the optimal lag order. Now recall that in a VECM (or the presumption of cointegration), the optimal lag order to use is p -1. To determine the optimal number of lags, we use the VARselect() command.
lagselect <- VARselect(dset, lag.max = 7, type = "const")lagselect$selection
Since 5 came up in the Hannan Quinn and the Final Prediction error, we choose to use 4 lags. 4 lags is expected given that the frequency of the data is quarterly. Now that we have our lag selection done, we can move on to specifying the test. As we mentioned, there are two variants of the Johansen test. These are the maximum eigenvalue and the trace statistic approach. Conveniently, the ca.jo() command allows us to specify these with ease.
We start off with the trace statistic approach. Again, the ca.jo() command implores the Johansen cointegration methodology on our system (dset). We use the “trace” statistic approach specified as the type in this case. Next, we specify that our specification has a constant (ecdet = “const”) and that we are using 4 lags.
ctest1t <- ca.jo(dset, type = "trace", ecdet = "const", K = 4)summary(ctest1t)
If you ran the test properly, you should see the table below.
In the table, you should see 4 columns. The test column contains the test statistics, while the three other columns contain the critical values at a 10 percent, 5 percent, and a 1 percent level. For this case, as standard practice, we often use the 5 percent critical value as reference. The r in the table represents the rank and we know that this is some indication of the number of cointegrating relationships. When r = 0, the test stat 87.77 > 22. This means that we reject the null hypothesis which suggests that r > 0. As such, there is some cointegration present. When r <1, 21.64 > 15.67. This again means that we reject the null hypothesis which suggests that r > 1. Lastly, when r < 2, we fail to reject the null hypothesis because 7.89 < 9.24. Therefore, we conclude that there are at most 2 cointegrating relationships present.
We can also run the test using the maximum eigenvalue variant using the commands below.
ctest1e <- ca.jo(dset, type = "eigen", ecdet = "const", K = 4)summary(ctest1e)
As we can see, we have similar results as with the trace approach. Overall, we can conclude that there are at least two cointegrating relationships present. By now, you will have connected the dots that these two relationships are likely prices and the money supply and prices and GDP. We will get into that later on once we formally estimate a VECM.
For a more illustrative explanation, check out my YouTube video linked below.
[1] Brooks, C. Introductory econometrics for finance.(2019) Cambridge university press.
[2] Hamilton, J. Time series econometrics. (1994) Princeton U. Press, Princeton.