Estimate local projection impulse response functions using horizon-specific linear regressions.
using Pkg
Pkg.add(url="https://github.com/gragusa/LocalProjections.jl")using LocalProjections, DataFrames, CovarianceMatrices, Plots
# Generate sample data
n = 200
shock = randn(n)
y = cumsum(shock) + 0.5 * randn(n) # y responds to cumulative shocks
df = DataFrame(y = y, shock = shock)
# Estimate local projections: y_{t+h} = α + β * shock_t + ε
# The coefficient β at each horizon h gives the impulse response
lp_result = lp(@formula(leads(y) ~ shock), df; horizon=20)
# Use HAC-robust standard errors (Newey-West); the default is HC1
lp_result = lp_result + vcov(Bartlett{NeweyWest}())
# Extract the impulse response function
irf = coefpath(lp_result; term=:shock)
se = stderror(lp_result; term=:shock)
# Plot IRF with 95% confidence bands
plot(lp_result; term=:shock, levels=[0.95])MIT License - see LICENSE for details.