Dynamic causal effects and distributed lags¶
Many interventions do not act instantaneously.
A promotion, policy, medication, campaign, or pricing change can have:
- a delayed response;
- persistence after exposure;
- multiple periods of carry-over;
- a cumulative effect that is much larger than the immediate effect.
A static treatment coefficient can therefore answer the wrong question.
Randomized dynamic-treatment DGP¶
The dynamic panel simulator generates randomized treatment episodes across regions and time.
Treatment assignment is independent of untreated potential outcomes by construction.
Outcomes also contain:
- persistent regional heterogeneity;
- common time shocks;
- deterministic seasonality;
- trend;
- AR(1) idiosyncratic errors.
The causal effect is a finite distributed lag:
[ \Delta_{it} = \sum_{\ell=0}^{L} \beta_{\ell}D_{i,t-\ell}. ]
The default kernel is
[ (\beta_0,\ldots,\beta_4) = (0, 2, 1.5, 1, 0.5). ]
There is no immediate effect, but the cumulative effect of a one-period impulse is
[ \sum_{\ell=0}^4 \beta_\ell = 5. ]
That gap between immediate and cumulative response is intentional.
Distributed-lag estimation¶
fit_distributed_lag creates current and lagged treatment regressors and fits
[ Y_{it} = \alpha_i + \gamma_t + \sum_{\ell=0}^{L} \beta_\ell D_{i,t-\ell} + \varepsilon_{it}. ]
Entity effects absorb time-invariant regional levels.
Time effects absorb seasonality, trend, and common period shocks.
The DGP randomizes treatment episodes, so the treatment history is sequentially exogenous by construction.
Entity-clustered covariance is used because residuals are serially correlated within region.
Immediate versus cumulative effects¶
The immediate effect is
[ \beta_0. ]
The cumulative impulse effect through horizon h is
[ C_h = \sum_{\ell=0}^{h}\beta_\ell. ]
The full cumulative effect is
[ C_L = \sum_{\ell=0}^{L}\beta_\ell. ]
cumulative_effect_at_horizon propagates the full coefficient covariance matrix:
[ \operatorname{Var}(C_h) = \mathbf{1}' \operatorname{Cov}(\hat\beta_{0:h}) \mathbf{1}. ]
This is preferable to summing standard errors independently.
Why a static model fails¶
A current-treatment-only model estimates
[ Y_{it} = \alpha_i + \gamma_t + \delta D_{it} + u_{it}. ]
When treatment persists for multiple periods, current treatment is correlated with omitted lagged treatment.
The coefficient delta therefore mixes the immediate effect with omitted carry-over effects.
In the default DGP, the true immediate effect is zero and the cumulative effect is five. The static coefficient is neither quantity.
compare_static_and_dynamic makes this failure explicit against known truth.
Treatment-history estimands¶
Dynamic causal effects depend on an exposure path, not just one binary treatment indicator.
For a treatment history
[ \mathbf d = (d_0,d_1,\ldots,d_T), ]
the induced effect path is the convolution of treatment history with the lag kernel:
[ \Delta_t(\mathbf d) = \sum_{\ell=0}^{L} \beta_\ell d_{t-\ell}. ]
evaluate_treatment_history computes:
- the period-by-period effect path;
- total effect over the observed horizon;
- peak effect;
- peak-effect period.
For a one-period impulse, the effect path is exactly the lag kernel.
For repeated treatment, lagged effects stack and create carry-over.
Serial correlation¶
The simulator includes AR(1) outcome noise:
[ u_{it} = \rho u_{i,t-1} + \eta_{it}. ]
Serial correlation changes uncertainty even when treatment is randomized.
The estimator therefore clusters uncertainty by region rather than using independent-observation standard errors.
Seasonality¶
Seasonality is included in the untreated outcome process.
Two-way time effects absorb common seasonal and trend structure without requiring the analyst to know the exact seasonal functional form.
In applications with few periods or unit-specific seasonality, more explicit seasonal modelling may be needed.
Identification¶
The dynamic methodology contract includes sequential exchangeability.
In the controlled DGP this is guaranteed by randomized treatment episodes.
In observational longitudinal data it is much harder: time-varying covariates can simultaneously predict future treatment and future outcomes, and can themselves be affected by earlier treatment.
A conventional distributed-lag regression does not automatically solve that problem.
The repository therefore uses this module to isolate dynamic-response estimation from the separate problem of time-varying confounding.