# -*- coding: utf-8 -*-
# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .r
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: R
#     language: R
#     name: ir
# ---

# ## <NAME> (2013) Combined Cointegration Approach
#
# * Existing applied economics literature provides many cointegration approaches to examine long-run relationship between macroeconomic variables. 
# * Before proceeding to cointegration approach, it is necessary to examine unit root properties of the variables, which helps in choosing suitable cointegration test for empirical model for reliable empirical results.
# * Existing cointegration approaches include Engle and Granger (1987) (EG), Johansen (1991) (JOH), Phillips and Ouliaris (1990), <NAME> (1994) (BO) and Banerjee $\it{et}$ $\it{al}$. (1998)(BDM). 
# * These cointegration approaches may provide ambiguous empirical results due to their explanatory power properties. 
# * Bayer and Hanck (2009 and 2013) developed a new cointegration approach known as the combined cointegration approach. This test combines the results of previous cointegration approaches (Johansen, Phillips and Ouliaris, Boswijk, and Banerjee) and provides Fisher F-statistics for more conclusive and reliable empirical findings. 
# * The Bayer and Hanck combined cointegration approach, the order of integration must be unique, i.e. $I(1)$. If the calculated F-statistic exceeds the critical value, we may reject the null of no cointegration; the reverse applies for the acceptance of the null hypothesis. 
#
#

# ### Fisher's formulas
# The Fisher's formulas of computing Bayer and Hanck cointegration are as follows:
#
# 𝐸𝐺−𝐽𝑂𝐻=−2[ln(P_EG)]
#
# 𝐸𝐺−𝐽𝑂𝐻−𝐵𝑂−𝐵𝐷𝑀=−2[ln(P_EG)+ln(P_JOH)+ln(P_BO)+ln(P_BDM)]
#
# * Where P_EG, P_JOH, P_BO, P_BDM are the p-values of various individual cointegration tests such as Engle and Granger (1987), Johansen (1991), <NAME> (1994) and Banerjee et al.(1998), respectively. 
# * The Fisher statistic is used to examine whether cointegration exists or not between the variables. We may reject the null hypothesis in favor of cointegration between the variables if the Fisher statistic exceeds the Bayer and Hanck critical bounds and vice versa.
#

# ### A joint test-Statistics for the Null of Non-Cointegration
# * <NAME>., & <NAME>., 2013. Combining non cointegration tests. Journal of Time Series Analysis,34,83–95. 
# * Bayerhanck produces a joint test-statistic for the null of non-cointegration based on Engle-Granger, Johansen maximum eigenvalue, Boswijk and Banerjee tests. https://rdrr.io/github/jens-klenke/bayerhanck/

library(readxl)
library(bayerhanck)
dataset <- read_excel("Book2Q.xlsx")

# dataframe attributes
str(dataset)

# descriptive statistics
summary(dataset[,2:4])

# model LRGDP = f(LREP,LUNEM) Test Statistics
englegranger(LRGDP ~ LREP + LUNEM, data = dataset, lags = 2, trend = "const")
johansen(LRGDP ~ LREP + LUNEM, data = dataset, type = "eigen", lags = 2, trend = "const")
banerjee(LRGDP ~ LREP + LUNEM, data = dataset, lags = 2, trend = "const")
boswijk(LRGDP ~ LREP + LUNEM, data = dataset, lags = 2, trend = "const")

# EG-JOH：lag 2, constant trend, significance level is 1%
egj1 = bayerhanck(LRGDP ~ LREP + LUNEM, data = dataset, lags = 2, trend = "const", test = "eg-j", crit = 0.01)
summary(egj1)

# EG-JOH：lag 2, constant trend, significance level is 5%
egj2 = bayerhanck(LRGDP ~ LREP + LUNEM, data = dataset, lags = 2, trend = "const", test = "eg-j", crit = 0.05)
summary(egj2)

# EG-JOH：lag 2, constant trend, significance level is 10%
egj3 = bayerhanck(LRGDP ~ LREP + LUNEM, data = dataset, lags = 2, trend = "const", test = "eg-j", crit = 0.10)
summary(egj3)

# EG-JOH-BO-BDM：lag 2, constant trend, significance level is 1%
bh1 = bayerhanck(LRGDP ~ LREP + LUNEM, data = dataset, lags = 2, trend = "const", test = "all", crit = 0.01)
summary(bh1)

#EG-JOH-BO-BDM：lag 2, constant trend, significance level is 5%
bh2 = bayerhanck(LRGDP ~ LREP + LUNEM, data = dataset, lags = 2, trend = "const", test = "all", crit = 0.05)
summary(bh2)

# EG-JOH-BO-BDM：lag 2, constant trend, significance level is 10%
bh3 = bayerhanck(LRGDP ~ LREP + LUNEM, data = dataset, lags = 2, trend = "const", test = "all", crit = 0.10)
summary(bh3)

# Bayer-Hanck Fisher Statistics with EG-JOH test
plot(egj2)

# Bayer-Hanck Fisher Statistics with EG-JOH-BO-BDM test
plot(bh2)

# ## Empirical Results 
# <table style="height: 137px;" width="657">
# <tbody>
# <tr style="height: 22px;">
# <td style="height: 22px; width: 281.333px;">&nbsp;<strong>Estimated models</strong>&nbsp;</td>
# <td style="height: 22px; width: 70px;">&nbsp;EG-JOH</td>
# <td style="height: 22px; width: 146px;">&nbsp;&nbsp;EG-JOH-BO-BDM&nbsp;</td>
# <td style="height: 22px; width: 54px;">&nbsp;&nbsp;Lags&nbsp;</td>
# <td style="height: 22px; width: 104.667px;">&nbsp;Cointegration&nbsp;</td>
# </tr>
# <tr style="height: 22px;">
# <td style="height: 22px; width: 281.333px;">&nbsp;$LRGDP_{t}= LREP_{t} + LUNEM_{t}$</td>
# <td style="height: 22px; width: 70px;">&nbsp;4.4554&nbsp;</td>
# <td style="height: 22px; width: 146px;">&nbsp;5.6672&nbsp;</td>
# <td style="height: 22px; width: 54px;">&nbsp;2&nbsp;</td>
# <td style="height: 22px; width: 104.667px;">&nbsp;No&nbsp;</td>
# </tr>
# <tr style="height: 22px;">
# <td style="height: 22px; width: 281.333px;">&nbsp;<strong>Significance Level</strong></td>
# <td style="height: 22px; width: 70px;">&nbsp;</td>
# <td style="height: 22px; width: 146px;">&nbsp;</td>
# <td style="height: 22px; width: 54px;">&nbsp;</td>
# <td style="height: 22px; width: 104.667px;">&nbsp;</td>
# </tr>
# <tr style="height: 22px;">
# <td style="height: 22px; width: 281.333px;">1%</td>
# <td style="height: 22px; width: 70px;">16.679</td>
# <td style="height: 22px; width: 146px;">32.077</td>
# <td style="height: 22px; width: 54px;">&nbsp;</td>
# <td style="height: 22px; width: 104.667px;">&nbsp;</td>
# </tr>
# <tr style="height: 22px;">
# <td style="height: 22px; width: 281.333px;">5%</td>
# <td style="height: 22px; width: 70px;">10.895</td>
# <td style="height: 22px; width: 146px;">21.106</td>
# <td style="height: 22px; width: 54px;">&nbsp;</td>
# <td style="height: 22px; width: 104.667px;">&nbsp;</td>
# </tr>
# <tr style="height: 22px;">
# <td style="height: 22px; width: 281.333px;">10%</td>
# <td style="height: 22px; width: 70px;">&nbsp;8.479</td>
# <td style="height: 22px; width: 146px;">&nbsp;16.444</td>
# <td style="height: 22px; width: 54px;">&nbsp;</td>
# <td style="height: 22px; width: 104.667px;">&nbsp;</td>
# </tr>
# </tbody>
# </table>



StarcoderdataJupyterScriptsDedupFiltered