Johansen cointegration test using R
Johansen Test Result from Johansen and Juselius (1990)
I will not cover cointegration theory here, as there are many excellent books on the topic, such as Analysis of Financial Time Series by Ruey S. Tsay. Instead, I will demonstrate how to replicate the cointegration test results from Johansen and Juselius (1990), as it can serve as a starting point or reference for further research.
In their influential paper, two datasets are utilized: Danish and Finnish data. Both datasets are analyzed using 2 lags and a quarterly seasonal dummy. The Danish dataset includes a constant in the cointegration equation, whereas the Finnish dataset does not use either a constant or a trend.
The target result is Table 3 on page 183 of Johansen and Juselius (1990), as presented below.
R code
Using the urca R package, the above results can be implemented as follows:
# Load the necessary package for cointegration library(urca) # Load the 'denmark' dataset data(denmark) # select data data <- as.matrix(denmark[,c(2,3,5,6)]) #===================================================== # Perform the Johansen cointegration test #===================================================== # - type = "trace" runs the trace test # alternatively, # use "eigen" for the max-eigenvalue test # # - ecdet = "none" for no intercept in cointegration, # "const" for constant term in cointegration # "trend" for trend variable in cointegration. # # - K = The lag order of the series (levels) in the VAR. # ex) K = 2 sets the lag length (1 lag difference) #===================================================== test_tr <- ca.jo(data, type = "trace", ecdet = "const", K = 2, season = 4) test_eg <- ca.jo(data, type = "eigen", ecdet = "const", K = 2, season = 4) result1 = data.frame(trace=round(test_tr@teststat,2), trace_95=test_tr@cval[,2], lamax=round(test_eg@teststat,2), lamax_95=test_eg@cval[,2]) # Load the 'finland' dataset data(finland) data2 <- as.matrix(finland) test_tr2 <- ca.jo(data2, type = "trace", ecdet = "none", K = 2, season = 4) test_eg2 <- ca.jo(data2, type = "eigen", ecdet = "none", K = 2, season = 4) result2 = data.frame(trace=round(test_tr2@teststat,2), trace_95=test_tr2@cval[,2], lamax=round(test_eg2@teststat,2), lamax_95=test_eg2@cval[,2]) print("The Danish data") result1 print("The Finnish data") result2 | cs |
We can see that this replication closely matches the original results, as shown in the output below.
Reference
Johansen, S. and Juselius, K. (1990), Maximum Likelihood Estimation and Inference on Cointegration – with Applications to the Demand for Money, Oxford Bulletin of Economics and Statistics, 52, 2, 169–210. \(\blacksquare\)
No comments:
Post a Comment