Skip to content

econometron.utils.projection.Localprojirf

  • Localprojirf class from econometron.utils.projection

Overview

The Localprojirf class is part of the econometron.models.localproj module and is designed to estimate Impulse Response Functions (IRFs) using the local projection method, a technique popularized by Jordà (2005) for analyzing the dynamic effects of shocks in time series data.

Localprojirf estimates IRFs by running a series of regressions where the dependent variable is the response of an endogenous variable at different forecast horizons, and the explanatory variables include a shock variable, lagged endogenous and exogenous variables, and an optional constant. It is particularly suited for analyzing the dynamic responses of economic variables to shocks in a flexible, non-parametric manner, often used in conjunction with DSGE models to estimate empirical IRFs or validate theoretical predictions.

Class Definition

The Localprojirf class is designed to estimate impulse response functions using local projection methods, supporting both endogenous and exogenous variables, with options for lags, constant terms, and robust standard errors.

Attributes

  • data: Copy of the input DataFrame.
  • endogenous_vars: List of endogenous variable names.
  • exogenous_vars: List of exogenous variable names (if provided).
  • H: Maximum forecast horizon.
  • lags: List of lag orders to include.
  • constant: Boolean indicating whether to include a constant term.
  • date_col: Name of the date column for sorting (if provided).
  • _prepared: Prepared DataFrame with lags (set after calling _prepare).
  • results_: Dictionary storing estimation results.
  • _impulse_vars: List of variables treated as impulses.

Initialization

python
from econometron.utils.projection import Localprojirf
model = Localprojirf(
    data=data,
    endogenous_vars=['fedfunds','ogap'],
    exogenous_vars=None,
    max_horizon=8,  
    lags=[1,2, 3 ,4],   
    constant=True,
    date_col=None
)

Parameters

ParameterType / Description
dataInput DataFrame.
endogenous_varsList of endogenous variable names.
exogenous_varsOptional list of exogenous variable names (for dynamic multipliers).
max_horizonMaximum forecast horizon (default 8)
lagsLags to include. If int, includes lags 1 through lags. If list, includes specific lags (default [1,2]).
constantWhether to include a constant term (default True).
date_colOptional date column name for sorting.

Methods

set_impulse_vars

python
def set_impulse_vars(self, impulse_vars: List[str])

Set which variables to treat as impulse variables.

Parameters:

  • impulse_vars: List of variable names to treat as impulses.

Returns:

  • Self, for method chaining.

Raises:

  • ValueError: If any impulse variable is not in endogenous or exogenous variables.

fit

python
def fit(self, response_vars: Optional[List[str]] = None, impulse_vars: Optional[List[str]] = None, 
        horizons: Optional[int] = None, difference: bool = False, cumulate: bool = False, 
        hac: bool = False, hac_lags: Optional[int] = None, robust: bool = False, 
        dfk: bool = False, small: bool = False)

Fit the local projection IRF model.

Parameters:

  • response_vars: List of response variables (default: all endogenous variables).
  • impulse_vars: List of impulse variables (default: all endogenous variables).
  • horizons: Maximum forecast horizon (default: self.H).
  • difference: If True, use differenced dependent variable.
  • cumulate: If True, use cumulative response.
  • hac: If True, use Newey-West HAC standard errors.
  • hac_lags: Number of lags for HAC estimation (default: automatic selection).
  • robust: If True, use White robust standard errors.
  • dfk: If True, apply degrees of freedom correction.
  • small: If True, use t-distribution for inference; otherwise, use normal.

Returns:

  • Self, for method chaining.

get_irf

python
def get_irf(self, response_var: str, impulse_var: str, level: float = 0.95) -> pd.DataFrame

Get IRF table with confidence intervals.

Parameters:

  • response_var: Name of the response variable.
  • impulse_var: Name of the impulse variable.
  • level: Confidence level for intervals (default: 0.95).

Returns:

  • DataFrame with IRF estimates, standard errors, test statistics, p-values, and confidence intervals.

Raises:

  • RuntimeError: If fit() has not been called.
  • ValueError: If response or impulse variable is not found in results.

summary

python
def summary(self) -> Dict[str, Any]

Return full results dictionary.

Returns:

  • Dictionary containing estimation results.

plot_irf

python
def plot_irf(self, response_var: str, impulse_var: str, 
             level: float = 0.95, title: Optional[str] = None, 
             figsize: tuple = (10, 6))

Plot IRF with confidence bands.

Parameters:

  • response_var: Name of the response variable.
  • impulse_var: Name of the impulse variable.
  • level: Confidence level for bands (default: 0.95).
  • title: Optional plot title.
  • figsize: Figure size as (width, height).

Returns:

  • Tuple of matplotlib figure and axes objects.

Raises:

  • RuntimeError: If fit() has not been called.

get_summary

python
def get_summary(self) -> str

Return a formatted string summary of IRF results.

Returns:

  • String with formatted IRF results, grouped by impulse variable.

Raises:

  • RuntimeError: If fit() has not been called.

Notes

  • Internal methods (_make_lags, _prepare, _auto_hac_lags, _nw_cov) are excluded from this documentation as they are not intended for external use.
  • Results are stored in the results_ attribute after calling fit(), accessible via summary() or get_irf().
  • Advantages:

    • Flexible and non-parametric compared to VAR-based IRFs.
    • Supports customization (differencing, cumulative responses, lag selection).
    • Robust standard errors via HAC estimation.
  • Dependencies:

    • econometron.utils.estimation.Regression.ols_estimator: For OLS regression.