Optional Python Appendix — Empirical Forecasting

Optional Python Lab 2 — Diagnose Stationarity

Compare ADF/KPSS evidence for differencing with a mechanism-aligned deterministic adjustment.

Optional Python Lab 2 — Diagnose Stationarity

Question

Do the data support first differencing, seasonal differencing, or explicit trend, month, and intervention terms with a stationary error?

ADF and KPSS provide evidence under specified deterministic terms; they do not choose the scientific mechanism. This lab uses both because their null hypotheses point in opposite directions.

Run the diagnostic table

Py

Compare transformations with ADF and KPSS

Idle

Read the nulls correctly

ADF resultKPSS resultInterpretation to investigate
small plarge pstationarity is plausible under the stated deterministic terms
large psmall punit-root/differencing route is plausible
both smallboth reject their nulls; inspect breaks, variance, or misspecification
both largesample may be weakly informative

P-values can be reported at tabulated bounds such as 0.01 or 0.10; software warnings about interpolation are not extra precision. The known 2023 step and the short sample make sensitivity analysis essential.

Why the adjusted route fits this simulation

The data-generating mechanism has fixed month effects and a deterministic step, not seasonal or ordinary unit roots. Regression adjustment therefore preserves interpretable level information while leaving the AR error for the next lab.

In real data, the mechanism is not revealed. Compare forecasts from both plausible routes rather than selecting by one p-value.

Transformation memo

In 120 words or fewer, state:

  1. deterministic terms used in each test;
  2. whether ADF and KPSS agree;
  3. which route matches the substantive mechanism;
  4. one alternative retained for backtesting;
  5. how a future intervention would be known at forecast origin.

Continue to Python Lab 3.

Copyright © 2026