Optional Python Lab 2 — Diagnose Stationarity
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
Compare transformations with ADF and KPSS
Read the nulls correctly
| ADF result | KPSS result | Interpretation to investigate |
|---|---|---|
| small p | large p | stationarity is plausible under the stated deterministic terms |
| large p | small p | unit-root/differencing route is plausible |
| both small | both reject their nulls; inspect breaks, variance, or misspecification | |
| both large | sample 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:
- deterministic terms used in each test;
- whether ADF and KPSS agree;
- which route matches the substantive mechanism;
- one alternative retained for backtesting;
- how a future intervention would be known at forecast origin.
Continue to Python Lab 3.