A Python function to perform ARDL cointegration analysis and estimate the Error Correction Model (ECM).
This Python function performs ARDL cointegration analysis and estimates the ECM model. It helps in:
- Selecting optimal lags using the AIC criterion (if
exog_ordersis not provided). - Estimating the Unrestricted Error Correction Model (UECM).
- Providing long-run (cointegrating) and short-run (ECM) model summaries.
- Plotting ARDL residuals (Error Correction Term - ECT), default error diagnostics, and CUSUM plots with 95% confidence bands.
- Automatic or manual lag selection for ARDL models.
- Estimation of UECM and ECM models.
- Long-run and short-run model summaries.
- Comprehensive error diagnostics and stability tests (CUSUM).
To run this function, you need the following libraries:
pandasnumpymatplotlibstatsmodels
# Import necessary libraries import pandas as pd from statsmodels.tsa.ardl import ardl_select_order, UECM import statsmodels.api as sm import matplotlib.pyplot as plt import warnings
ardl_model( dataset=dataframe, y="dependent_variable", X=["independent_variable1", "independent_variable2"], max_lag=4, exog_orders=None # or provide a list of lag orders for exogenous variables )
dataset: The dataset as a Pandas DataFrame.y: The dependent variable (string).X: List of independent variable(s).max_lag: Maximum lag order for selection.exog_orders: List of manually determined lag orders for exogenous variable(s). IfNone, the function automatically selects lags.
- The UECM (unconstrained) model
- Long-run (cointegrating) model summary
- Short-run (ECM) model summary
- Plot of the ARDL residuals (ECT)
- Plot of default error diagnostics
- The CUSUM plots with 95% confidence bands
# Example usage import pandas as pddf = pd.read_csv("your_dataset.csv")
ardl_model( dataset=df, y="Y_variable", X=["X1", "X2", "X3"], max_lag=3, exog_orders=None )
- If
exog_ordersis not provided, the function will automatically select the optimal lags using the AIC criterion. - Ensure that your dataset is free of missing values, as NA values can cause errors during lagging.
- Use
exog_ordersto manually specify lag orders if the automatic selection fails.
This project is licensed under the MIT License.
Developed by Patrick Onodje. Feel free to reach out for any questions or collaborations on patrickonodje@live.com.