*! version 1.0.0 15mar2026

Title

ivlpirf2 -- IV local-projection impulse-response functions with
panel data and Driscoll-Kraay inference

Syntax

Time-series estimation:

ivlpirf2
depvarlist
[if] [in]
, endogenous(depvar = instruments)
[options]

Panel-data estimation with Driscoll-Kraay:

ivlpirf2
depvarlist
[if] [in]
, endogenous(depvar = instruments)
vce(dkraay) fe
[options]

Main
endogenous(depvar = varlist) endogenous impulse variable and instruments (required)

step(#) maximum IRF horizon; default is 4

lags(numlist) control lag orders; default is 1 2

exog(varlist) additional exogenous controls

vce(type) variance estimator: robust, cluster clustvar, hac nw [#], or dkraay [#]

fe panel fixed effects

cumulative report cumulative impulse responses

noconstant suppress intercept

graph plot IRF with layered confidence bands

level(numlist) confidence levels; default is 68 90 95

firststage report first-stage F-statistics for weak instruments

method(string) estimation method: 2sls (default) or gmm

notable suppress output table

title(string) custom graph title

saving(string) save graph to file

The data must be tsset or xtset before using ivlpirf2.

Description

ivlpirf2 estimates impulse-response functions (IRFs) using the local
projection (LP) method of Jordà (2005) with
instrumental variables. Unlike traditional VAR-based IRFs, local projections
estimate each horizon's response directly via separate regressions, making
them robust to model misspecification.

Key features:

1. IV estimation — Instruments an endogenous impulse variable
using external instruments via 2SLS.

2. Panel data support — Works with xtset panel data,
including fixed effects (fe).

3. Driscoll-Kraay SEs — Robust to heteroskedasticity, serial
correlation, and cross-sectional dependence via vce(dkraay).

4. Publication-quality graphs — Layered confidence bands
(68%, 90%, 95%) with shaded regions.

5. Weak-instrument diagnostics — First-stage F-statistics
via firststage.

Compatibility: Requires Stata 14 or later. Works with both time-series
and panel data.

Options

Main

endogenous(depvar = varlist) specifies the endogenous impulse variable
and the instruments. Only one endogenous variable is allowed. Multiple
instruments may be specified.

step(#) sets the maximum IRF horizon. Default is 4. For each
horizon h = 0, 1, ..., step, a separate regression is estimated.

lags(numlist) specifies lag orders for control variables. Default is
1 2. Controls include lags of all response variables and the
endogenous variable.

exog(varlist) specifies additional exogenous covariates to include
in all regressions.

vce(type) specifies the variance estimator:

robust -- (default) Heteroskedasticity-robust (Eicker-Huber-White).

cluster clustvar -- Cluster-robust at the level of clustvar.

hac nw [#] -- Newey-West HAC standard errors. Optional lag
truncation parameter.

dkraay [#] -- Driscoll-Kraay standard errors. Requires panel
data. Optional bandwidth parameter. Robust to heteroskedasticity, serial
correlation, and cross-sectional dependence.

fe includes panel fixed effects. Requires panel data (xtset).

cumulative reports cumulative impulse-response functions (sum of
responses from horizon 0 to h).

graph produces a publication-quality IRF plot with layered confidence
bands. Uses the cranberry color scheme with shaded regions for each
confidence level.

level(numlist) specifies the confidence levels for the graph. Default
is 68 90 95, producing three layered bands. The innermost band is the
darkest.

firststage reports first-stage regression diagnostics for the
instruments, including the F-statistic on excluded instruments. An F < 10
suggests potential weak instruments (Stock and Yogo, 2005).

Methods and Formulas

Local Projections (Jordà, 2005)

For each horizon h, the LP regression is:

y_ = alpha_h + beta_h * x_t + Gamma_h' * W_t + u_

where y_ is the response variable at horizon h, x_t is the endogenous
impulse variable instrumented by z_t, and W_t contains lagged controls.
The collection of beta_h coefficients traces the IRF.

IV Estimation

When x_t is endogenous, 2SLS is used: the first stage regresses x_t on
z_t and W_t; the second stage uses fitted values. For panel data with
fe, within-transformation is applied first.

Driscoll-Kraay Standard Errors

For panel data with cross-sectional dependence (e.g., common shocks),
Driscoll and Kraay (1998) standard errors are
consistent under:

(a) heteroskedasticity

(b) arbitrary serial correlation

(c) cross-sectional dependence when T is moderate

This is implemented via xtscc (Hoechle, 2007).

GMM Joint Estimation

With method(gmm), all horizons are estimated simultaneously using
Stata's gmm command. Controls are partialled out from the dependent
variables, the endogenous variable, and the instruments via OLS residuals.
The GMM moment conditions are:

E[z_t * (y_ - beta_h * x_)] = 0 for h = 0, ..., H

where the subscript po denotes partialled-out variables. This produces
a joint variance-covariance matrix across all horizons, accounting for
cross-horizon correlation. This is the same approach used by Stata 19's
built-in ivlpirf. See
Plagborg-Møller and Wolf (2021) for theoretical
equivalence results.

Stored Results

ivlpirf2 stores the following in e():

Scalars:

e(N) number of observations

e(step) maximum horizon

e(k_impulses) number of impulse variables (always 1)

e(k_responses) number of response variables

e(k_instruments) number of instruments

e(k_controls) number of control variables

e(cumul) 1 if cumulative, 0 otherwise

Macros:

e(cmd) ivlpirf2

e(impulse) impulse variable name

e(responses) response variable names

e(instruments) instrument variable names

e(vce) VCE type

Matrices:

e(b) coefficient vector (IRF at each horizon)

e(V) variance-covariance matrix

e(irf_b) (step+1) x k_resp matrix of IRF coefficients

e(irf_se) (step+1) x k_resp matrix of standard errors

e(irf_df) (step+1) x k_resp matrix of degrees of freedom

Examples

Example 1: Basic time-series IV-LP IRF

Setup:

. webuse lutkepohl2, clear

. tsset

Estimate IRF of investment and consumption to an income shock,
instrumented by its own lags:

. ivlpirf2 dln_inv dln_consump, endogenous(dln_inc = L(2/4).dln_inc) step(8) graph

Example 2: Panel data with Driscoll-Kraay inference

For panel data with common shocks:

. xtset country year

. ivlpirf2 D.gdp, endogenous(shock = z_instrument) vce(dkraay) fe step(4) graph

This produces an IRF with layered 68/90/95% confidence bands using
Driscoll-Kraay standard errors, which are robust to cross-sectional
dependence.

Example 3: Cumulative IRF with cluster SEs

. ivlpirf2 dln_inv, endogenous(dln_inc = L(2/4).dln_inc) step(12) cumulative vce(cluster id) graph

Example 4: Weak instrument diagnostics

. ivlpirf2 dln_inv, endogenous(dln_inc = L(2/4).dln_inc) step(8) firststage

If the first-stage F-statistic is below 10, the instruments may be
weak and the IV estimates unreliable.

Example 5: Custom confidence levels

. ivlpirf2 dln_inv, endogenous(dln_inc = L(2/4).dln_inc) step(8) graph level(90 95)

This plots only two confidence bands (90% and 95%).

References

Driscoll, J.C. and A.C. Kraay. 1998.
Consistent covariance matrix estimation with spatially dependent panel data.
Review of Economics and Statistics 80(4): 549-560.

Hoechle, D. 2007.
Robust standard errors for panel regressions with cross-sectional dependence.
Stata Journal 7(3): 281-312.

Gertler, M. and P. Karadi. 2015.
Monetary policy surprises, credit costs, and economic activity.
American Economic Journal: Macroeconomics 7(1): 44-76.

Jordà, Ò. 2005.
Estimation and inference of impulse responses by local projections.
American Economic Review 95(1): 161-182.

Jordà, Ò., S.R. Singh, and A.M. Taylor. 2020.
The long-run effects of monetary policy.
NBER Working Paper No. 26666.

Mertens, K. and M.O. Ravn. 2013.
The dynamic effects of personal and corporate income tax changes in the
United States.
American Economic Review 103(4): 1212-1247.

Montiel Olea, J.L. and M. Plagborg-Møller. 2021.
Local projection inference is simpler and more robust than you think.
Econometrica 89(4): 1789-1823.

Newey, W.K. and K.D. West. 1987.
A simple, positive semi-definite, heteroskedasticity and autocorrelation
consistent covariance matrix.
Econometrica 55(3): 703-708.

Plagborg-Møller, M. and C.K. Wolf. 2021.
Local projections and VARs estimate the same impulse responses.
Econometrica 89(2): 955-980.

Ramey, V.A. 2016.
Macroeconomic shocks and their propagation.
In J.B. Taylor and H. Uhlig (eds.), Handbook of Macroeconomics,
vol. 2A. Elsevier: 71-162.

Saadaoui, J. and W. Ginn. 2025.
Monetary policy reaction to geopolitical risks in unstable environments.
Macroeconomic Dynamics, forthcoming.

Saadaoui, J. and V. Mignon. 2024.
How do political tensions and geopolitical risks impact oil prices?
Energy Economics 129: 107219.

Barbier-Gauchard, A., J. Saadaoui, and J.-E. Sturm. 2025.
Geopolitical risks, political tensions and the European economy.
European Journal of Political Economy, forthcoming.

Stock, J.H. and M.W. Watson. 2018.
Identification and estimation of dynamic causal effects in macroeconomics
using external instruments.
Economic Journal 128(610): 917-948.

Stock, J.H. and M. Yogo. 2005.
Testing for weak instruments in linear IV regression.
In D.W.K. Andrews and J.H. Stock (eds.), Identification and Inference
for Econometric Models. Cambridge University Press: 80-108.

Author

Dr. Merwan Roudane

Email: merwanroudane920@gmail.com

Please cite as:

Roudane, M. 2026. ivlpirf2: IV local-projection impulse-response
functions with panel data and Driscoll-Kraay inference. Stata package
version 1.0.0.