R: A Simple Replication of Cointegration Test Results

    Date:

    This post is a straightforward replication of the Johansen cointegration test results from Johansen and Juselius (1990) using R urca package.

    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

    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. 

    Originally posted on SHLee AI Financial Model blog.

    Disclosure: Interactive Brokers

    Information posted on IBKR Campus that is provided by third-parties does NOT constitute a recommendation that you should contract for the services of that third party. Third-party participants who contribute to IBKR Campus are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.

    This material is from SHLee AI Financial Model and is being posted with its permission. The views expressed in this material are solely those of the author and/or SHLee AI Financial Model and Interactive Brokers is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to buy or sell any security. It should not be construed as research or investment advice or a recommendation to buy, sell or hold any security or commodity. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.

    Go Source

    Chart

    SignUp For Breaking Alerts

    New Graphic

    We respect your email privacy

    Share post:

    Popular

    More like this
    Related

    How to Start Investing with IBKR

    Starting an investment process can seem daunting. In this...

    Rethinking Asset Growth in Asset Pricing Models

    Your Privacy When you visit any website it may use...

    China’s Turning Point: Inside the Stimulus Plan

    This podcast episode features Andrew Wilkinson and Dr. Xiaolin...

    Chart Advisor: Approaching Nvidia’s Earnings Report

    From SIA Charts 1/ Nvidia Corp. (NVDA) 2/ Matrix 3/ Candlestick Chart Investopedia is...