econometron.utils.projection.Localprojirf
Localprojirfclass fromeconometron.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
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
| Parameter | Type / Description |
|---|---|
data | Input DataFrame. |
endogenous_vars | List of endogenous variable names. |
exogenous_vars | Optional list of exogenous variable names (for dynamic multipliers). |
max_horizon | Maximum forecast horizon (default 8) |
lags | Lags to include. If int, includes lags 1 through lags. If list, includes specific lags (default [1,2]). |
constant | Whether to include a constant term (default True). |
date_col | Optional date column name for sorting. |
Methods
set_impulse_vars
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
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: IfTrue, use differenced dependent variable.cumulate: IfTrue, use cumulative response.hac: IfTrue, use Newey-West HAC standard errors.hac_lags: Number of lags for HAC estimation (default: automatic selection).robust: IfTrue, use White robust standard errors.dfk: IfTrue, apply degrees of freedom correction.small: IfTrue, use t-distribution for inference; otherwise, use normal.
Returns:
Self, for method chaining.
get_irf
def get_irf(self, response_var: str, impulse_var: str, level: float = 0.95) -> pd.DataFrameGet 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: Iffit()has not been called.ValueError: If response or impulse variable is not found in results.
summary
def summary(self) -> Dict[str, Any]Return full results dictionary.
Returns:
- Dictionary containing estimation results.
plot_irf
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: Iffit()has not been called.
get_summary
def get_summary(self) -> strReturn a formatted string summary of IRF results.
Returns:
- String with formatted IRF results, grouped by impulse variable.
Raises:
RuntimeError: Iffit()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 callingfit(), accessible viasummary()orget_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.
