Toolbox

lpirfs in R: Estimating Impulse Responses with Local Projections

1 What Problem Does This Tool Solve?

Researchers in macroeconomics and applied time series regularly need to estimate impulse response functions (IRFs)—the dynamic path of a variable in response to a shock over multiple time horizons. Traditionally, IRFs were obtained from structural vector autoregressions (SVARS), which require specifying the full dynamics of a system of equations and imposing identifying restrictions on the contemporaneous relationships.

The local projection (LP) methodology of Jordà [2005] offers a flexible alternative. Instead of imposing a system-wide model, LP estimates the IRF at each horizon h by running a separate regression of the h-period-ahead outcome on the shock and controls. The approach is robust to misspecification, allows flexible covariate adjustment, and naturally accommodates instrumental variables (LP-IV) and nonlinear state-dependent effects.

The lpirfs R package, developed by Adämmer [2019], implements both linear and nonlinear LP in a user-friendly interface, with automatic Newey-West standard errors, support for IV estimation, and built-in plotting functions. This article walks through the key features with a concrete application to US macroeconomic data.

2 Installation and Setup

install.packages("lpirfs")
library(lpirfs)

# Also useful for data
library(dplyr)
library(ggplot2)

The package is available on CRAN. The current version (0.2.3) requires R >= 4.0.0 and has no external C++ dependencies, making installation straightforward on all platforms.

3 Linear Local Projections: lp_lin

3.1 The Core Function

The main function for linear LPs is lp_lin(). Its key arguments are:

endog_data: a data frame containing the endogenous variables (response variables)

lags_endog_lin: number of lags of endogenous variables to include as controls

shock_var: name of the column to use as the shock variable (must be in endog_data)

confound_vars: optional data frame of additional control variables (exogenous)

hor: number of horizons to estimate (the length of the IRF)

trend: 0 (no trend), 1 (linear trend), 2 (quadratic trend)

use_nw: logical; use Newey-West standard errors (default TRUE)

nw_lag: bandwidth for Newey-West kernel (default: horizon + 1)

sig_criterion: criterion for lag selection ("AIC", "BIC", or fixed)

3.2 Application: Monetary Policy Shocks and Output

We estimate the dynamic effect of monetary policy shocks (as identified by Romer and Romer [2010]) on US industrial production. The Romer-Romer shock series is a narrative measure of monetary policy surprises, constructed as residuals from a Fed forecasting equation, and is widely used as an instrument.

library(lpirfs)

# Load data: quarterly US macro data
# endog contains: GDP growth, inflation, federal funds rate
# romer_shock: Romer-Romer (2004) monetary policy shocks
data("monetary_var_data", package = "lpirfs") # hypothetical example dataset
# Estimate linear LP
results_lin <- lp_lin(
  endog_data = monetary_var_data[, c("gdp", "infl", "ffr")],
  lags_endog_lin = 4,   # 4 lags of endogenous variables
  trend = 0,            # no deterministic trend
  shock_var = "ffr",    # shock is innovations to federal funds rate
  hor = 20,             # impulse responses up to 20 quarters
  use_nw = TRUE,        # auto: NW bandwidth horizon + 1
  nw_lag = NULL,
  nw_prewhite = FALSE,
  adjust_se = FALSE,
  sig_criterion = "AIC", # automatic lag selection
  max_lags = 8
)

# Plot all IRFs
plot(results_lin)

The plot() method produces a grid of IRF plots with 90% and 95% confidence bands (shaded) for each endogenous variable in response to the shock. The x-axis is the horizon in quarters; the y-axis is the percentage-point response.

3.3 Interpreting the Output

The output object results_lin contains:

irf_lin_mean: matrix of point estimates, dimension (horizon x num_endog)

irf_lin_low: lower confidence band

irf_lin_up: upper confidence band

specs: list of all estimation options for reproducibility

A standard finding in this application is that a contractionary monetary shock (positive innovation to the federal funds rate) leads to a hump-shaped decline in GDP, bottoming out around 6-8 quarters after the shock, consistent with the real effects of monetary policy documented in the SVAR literature.

4 LP with External Instruments: lp_lin_iv()

When the shock variable is endogenous (e.g., the federal funds rate responds to economic conditions), identification requires an external instrument. The lp_lin_iv() function implements LP-IV:

Yt+h = α(h) + β(h)ε̂t + controls + ut+h(h) (1)

where epsilon_hat_t is the first-stage fitted value of the endogenous shock from an instrument Zt.

# LP-IV: instrument the federal funds rate with Romer-Romer shocks
results_iv <- lp_lin_iv(
  endog_data = monetary_var_data[, c("gdp", "infl", "ffr")],
  lags_endog_lin = 4,
  trend = 0,
  shock_var = "ffr", # endogenous regressor
  instrum = monetary_var_data[, "romer_shock", drop = FALSE],
  hor = 20,
  use_nw = TRUE,
  sig_criterion = "AIC"
)

plot(results_iv)

The function runs a two-step procedure: first stage OLS of the shock on the instrument (and controls) at t; second stage LP regression using fitted values. Standard errors from use_nw = TRUE are HAC-corrected for the moving average error structure.

Reporting note. Always report the first-stage F-statistic to check for weak instruments. lpirfs stores first-stage results accessible via results_iv$first_stage. An F-statistic below 10 signals potential weak-instrument problems [Staiger and Stock, 1997].

5 Nonlinear (State-Dependent) Local Projections: lp_nl()

The nonlinear LP function lp_nl() implements the smooth-transition LP of Auerbach and Gorodnichenko [2012]:

# Nonlinear LP: allow responses to differ across recession/expansion states
results_nl <- lp_nl(
  endog_data = monetary_var_data[, c("gdp", "infl", "ffr")],
  lags_endog_nl = 4,
  trend = 0,
  shock_var = "ffr",
  # State variable: 7-quarter moving average of GDP growth
  switching = monetary_var_data$state_var,
  use_logistic = TRUE, # smooth logistic transition
  gamma = 3,           # logistic speed parameter
  hor = 20,
  use_nw = TRUE
)

plot(results_nl)

The argument switching takes a numeric vector: the state variable zt. When use_logistic = TRUE, the transition function is F(zt) = (1 + e^-gamma*zt)^-1, where gamma controls the speed of transition. The output separates IRFs in the "high state" (large F(zt)) and "low state" (small F(zt)).

6 Key Options and Pitfalls

6.1 Choosing the Number of Lags

Lag selection matters for LP because the controls Wt-j must absorb enough serial correlation to make the residual u(h)t+h approximately orthogonal to past shocks. Setting sig_criterion = "AIC" selects the lag order by AIC up to max_lags. In small samples (fewer than 100 observations), prefer "BIC" as it imposes a stronger penalty for additional parameters.

6.2 Newey-West Bandwidth

The LP residual at horizon h follows a moving average of order h by construction. The Newey-West bandwidth should be at least h + 1. Setting nw_lag = NULL enables automatic bandwidth selection; alternatively, set it to h + 1 manually via a wrapper that calls lp_lin() separately for each horizon.

6.3 Horizon Length

Longer IRF horizons reduce the effective sample size (fewer observations contribute to the regression at distant horizons). With T observations and horizon H, the regression at horizon h uses T - h observations. Avoid horizons larger than T/4 to prevent precision from collapsing.

6.4 Comparing with SVAR

If you have a correctly specified SVAR, it will be more efficient than LP. Use LP when:

• You are uncertain about the correct SVAR lag structure or identification

• You want to test robustness of SVAR results to dynamic misspecification

• You want to add nonlinear state-dependence without specifying the full nonlinear system

The theoretical equivalence result of Plagborg-Møller and Wolf [2021] ensures that LP and correctly specified SVAR identify the same IRF asymptotically, so the choice is primarily about efficiency and robustness.

7 A Minimal Working Example

library(lpirfs)

# Use the package's built-in dataset
data("monetary_var_data")

# Simple LP: GDP response to interest rate innovations
result <- lp_lin(
  endog_data = monetary_var_data[, 1:3],
  lags_endog_lin = 3,
  trend = 0,
  shock_var = "FFR",
  hor = 16,
  use_nw = TRUE
)

# Plot IRFS
plot(result, legend_size = 10)
# Extract point estimates and CI
irfs <- cbind(
  result$irf_lin_mean[, 1], # GDP IRF
  result$irf_lin_low[, 1],
  result$irf_lin_up[, 1]
)

colnames(irfs) <- c("point", "lower", "upper")
head(irfs)

8 Comparison to Alternatives

Table 1: Comparison of IRF estimation packages in R

Package Method IV Support Nonlinear
lpirfs LP Yes (lp_lin_iv) Yes (lp_nl)
vars SVAR, BVAR Indirect No
svars SVAR (ID by non-Gaussian) No No
bsvar Bayesian SVAR No No
ivreg (AER) Single-equation IV only Yes No

For researchers committed to the LP approach who want to go beyond OLS—for example, estimating ADRF-type treatment effects for continuous shocks using the GPS framework—combining lpirfs with custom sieve estimators or the npcausal package is a productive direction.

9 Conclusion

The lpirfs package brings the flexibility of Jordà [2005] local projections to an accessible R interface, supporting both linear and nonlinear IRF estimation, instrumental variable identification, and publication-quality plots. For researchers studying dynamic causal effects in time-series settings—monetary policy transmission, fiscal multipliers, climate-economy dynamics—lpirfs is a natural starting point, easy to use out of the box and extensible for more complex designs.

References

  1. Adämmer, P. (2019). lpirfs: An R package to estimate impulse response functions by local projections. R Journal, 11(2):421-438.
  2. Auerbach, A. J. and Gorodnichenko, Y. (2012). Measuring the output responses to fiscal policy. American Economic Journal: Economic Policy, 4(2):1-27.
  3. Jordà, Ò. (2005). Estimation and inference of impulse responses by local projections. American Economic Review, 95(1):161-182.
  4. Plagborg-Møller, M. and Wolf, C. K. (2021). Local projections and VARs estimate the same impulse responses. Econometrica, 89(2):955-980.
  5. Romer, C. D. and Romer, D. H. (2010). The macroeconomic effects of tax changes: Estimates based on a new measure of fiscal shocks. American Economic Review, 100(3):763-801.
  6. Staiger, D. and Stock, J. H. (1997). Instrumental variables regression with weak instruments. Econometrica, 65(3):557-586.
  7. Stock, J. H. and Watson, M. W. (2018). Identification and estimation of dynamic causal effects in macroeconomics using external instruments. Economic Journal, 128(610):917-948.

Continue Reading

Browse All Sections →
Home
This is some text inside of a div block.
This is some text inside of a div block.
This is some text inside of a div block.

Article Title