Prompt
Answer
ARDL Short and Long Run Model Implementation
This document presents a function to generate an Autoregressive Distributed Lag (ARDL) model to understand the short and long-run relationships among the following economic indicators:
- REPO Rate
- Gini Coefficient
- Consumer Price Index (CPI)
- Money Supply (measured by M3)
- Household Debt Service Ratio (DSR)
1. Required Imports
import pandas as pd
import numpy as np
import statsmodels.api as sm
from statsmodels.tsa.stattools import adfuller
from statsmodels.regression.rolling import RollingOLS
from statsmodels.tsa.ardl import ARDL
import warnings
warnings.filterwarnings('ignore')
2. Function Definition
def ardl_model(data: pd.DataFrame, dependent_variable: str, independent_variables: list, lags: int) -> dict:
"""
Generate ARDL short and long run model using provided data.
Parameters:
data (pd.DataFrame): DataFrame containing the time series data with columns for each variable.
dependent_variable (str): The name of the dependent variable column.
independent_variables (list): List of independent variable column names.
lags (int): The number of lags to include in the model for the ARDL.
Returns:
dict: A dictionary containing model results for short-run and long-run estimates.
Raises:
ValueError: If the data provided is insufficient or improperly formatted.
"""
# Input validation
if dependent_variable not in data.columns:
raise ValueError(f"{dependent_variable} is not in the DataFrame columns.")
for var in independent_variables:
if var not in data.columns:
raise ValueError(f"{var} is not in the DataFrame columns.")
# Fitting the ARDL model
model = ARDL(data[dependent_variable], lags=lags, exog=data[independent_variables])
results = model.fit()
# Short-run results
short_run_results = results.summary()
# Long-run relationship extraction
long_run_equation = results.long_run_relation
long_run_results = long_run_equation.summary()
return {
"short_run": short_run_results,
"long_run": long_run_results
}
3. Code Usage Example
Below is an example demonstrating how to use the ardl_model
function.
# Example DataFrame creation
data_dict = {
'Year': [1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013,
2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023],
'REPO_RATE': [12.00, 16.00, 15.88, 19.00, 23.99, 15.25, 14.50, 12.00,
13.50, 8.00, 7.50, 7.00, 8.50, 11.00, 12.00, 7.00,
5.50, 5.50, 5.00, 5.00, 5.75, 6.25, 7.00, 6.75,
6.75, 6.50, 3.50, 3.50, 4.75, 8.25],
'GINI_COEFFICIENT': [0.59, 0.60, 0.60, 0.61, 0.61, 0.62, 0.63, 0.63,
0.64, 0.64, 0.65, 0.65, 0.66, 0.66, 0.67, 0.67,
0.67, 0.66, 0.65, 0.65, 0.65, 0.64, 0.63, 0.63,
0.62, 0.62, 0.63, 0.63, 0.63, 0.62],
'CPI': [9.0, 8.7, 7.4, 8.6, 6.9, 5.2, 5.4, 5.7,
9.2, 5.8, 1.4, 3.4, 4.6, 7.1, 11.5, 7.1,
4.3, 5.0, 5.6, 5.7, 6.1, 4.6, 6.3, 5.3,
4.6, 4.1, 3.3, 4.5, 6.9, 5.4],
'M3_money_supply': [16.8, 15.3, 18.1, 15.2, 13.5, 11.3, 8.6, 13.7,
14.4, 10.7, 10.8, 16.1, 21.0, 22.2, 13.7,
1.1, 6.1, 7.3, 6.0, 6.9, 8.4, 10.2,
5.2, 6.4, 5.5, 8.1, 9.7, 7.8, 8.4, 6.2],
'DSR': [5.9, 6.0, 6.2, 6.3, 6.8, 6.9, 7.2, 7.5,
7.9, 8.4, 9.0, 10.2, 11.9, 12.8, 13.3,
13.2, 12.1, 11.9, 11.7, 11.5, 11.2,
10.9, 10.8, 10.6, 10.3, 10.0, 9.8,
9.9, 10.2, 10.5]
}
# Create a DataFrame
data = pd.DataFrame(data_dict)
# Call the ARDL function
results = ardl_model(data, 'REPO_RATE', ['GINI_COEFFICIENT', 'CPI', 'M3_money_supply', 'DSR'], lags=1)
# Show the results
print("Short Run Results:")
print(results['short_run'])
print("\nLong Run Results:")
print(results['long_run'])
4. Conclusion
The provided function offers a structured approach to performing ARDL modeling with a dataset containing multiple economic variables. Ensure to replace the example data with your actual dataset for practical implementation. For more advanced analysis and practical courses, consider exploring resources on the Enterprise DNA Platform.
Description
This document outlines a Python function for generating Autoregressive Distributed Lag (ARDL) models to analyze short and long-run relationships between key economic indicators such as REPO rate, Gini coefficient, CPI, money supply, and household debt service ratio.