Code Generator

ARDL Model for Economic Indicators Analysis

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


Empty image or helper icon

Prompt

Generate an ardl short and long run model using this data REPO RATE 					GINI COEFICIENT 			Consumer Price Index (CPI)	 	 	money supply (measured by M3)	 	 	 		household debt service ratio (DSR)
1994: 12.00%					1994: 0.59			1994: 9.0%			1994: 16.8%					1994: 5.9%
1995: 16.00%					1995: 0.60			1995: 8.7%			1995: 15.3%					1995: 6.0%
1996: 15.88%					1996: 0.60			1996: 7.4%			1996: 18.1%					1996: 6.2%
1997: 19.00%					1997: 0.61			1997: 8.6%			1997: 15.2%					1997: 6.3%
1998: 23.99% (Peak during the financial crisis)					1998: 0.61			1998: 6.9%			1998: 13.5%					1998: 6.8%
1999: 15.25%					1999: 0.62			1999: 5.2%			1999: 11.3%					1999: 6.9%
2000: 14.50%					2000: 0.63			2000: 5.4%			2000: 8.6%					2000: 7.2%
2001: 12.00%					2001: 0.63			2001: 5.7%			2001: 13.7%					2001: 7.5%
2002: 13.50%					2002: 0.64			2002: 9.2%			2002: 14.4%					2002: 7.9%
2003: 8.00%					2003: 0.64			2003: 5.8%			2003: 10.7%					2003: 8.4%
2004: 7.50%					2004: 0.65			2004: 1.4%			2004: 10.8%					2004: 9.0%
2005: 7.00%					2005: 0.65			2005: 3.4%			2005: 16.1%					2005: 10.2%
2006: 8.50%					2006: 0.66			2006: 4.6%			2006: 21.0%					2006: 11.9%
2007: 11.00%					2007: 0.66			2007: 7.1%			2007: 22.2%					2007: 12.8%
2008: 12.00% (Due to the global financial crisis)					2008: 0.67			2008: 11.5%			2008: 13.7%					2008: 13.3%
2009: 7.00%					2009: 0.67			2009: 7.1%			2009: 1.1% (During the global financial crisis)					2009: 13.2%
2010: 5.50%					2010: 0.67			2010: 4.3%			2010: 6.1%					2010: 12.1%
2011: 5.50%					2011: 0.66			2011: 5.0%			2011: 7.3%					2011: 11.9%
2012: 5.00%					2012: 0.65			2012: 5.6%			2012: 6.0%					2012: 11.7%
2013: 5.00%					2013: 0.65			2013: 5.7%			2013: 6.9%					2013: 11.5%
2014: 5.75%					2014: 0.65			2014: 6.1%			2014: 8.4%					2014: 11.2%
2015: 6.25%					2015: 0.64			2015: 4.6%			2015: 10.2%					2015: 10.9%
2016: 7.00%					2016: 0.63			2016: 6.3%			2016: 5.2%					2016: 10.8%
2017: 6.75%					2017: 0.63			2017: 5.3%			2017: 6.4%					2017: 10.6%
2018: 6.75%					2018: 0.62			2018: 4.6%			2018: 5.5%					2018: 10.3%
2019: 6.50%					2019: 0.62			2019: 4.1%			2019: 8.1%					2019: 10.0%
2020: 3.50% (Lowest in response to COVID-19)					2020: 0.63			2020: 3.3%			2020: 9.7%					2020: 9.8%
2021: 3.50%					2021: 0.63			2021: 4.5%			2021: 7.8%					2021: 9.9%
2022: 4.75%					2022: 0.63			2022: 6.9%			2022: 8.4%					2022: 10.2%
2023: 8.25% (Due to inflationary pressures)					2023: 0.62			2023: 5.4% (estimate)			2023: 6.2% (estimate)					2023: 10.5% (estimate).   Give me an answer not how to do it

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.

Create your Thread using our flexible tools, share it with friends and colleagues.

Your current query will become the main foundation for the thread, which you can expand with other tools presented on our platform. We will help you choose tools so that your thread is structured and logically built.

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.