Skip to content
Module 10 of 1255 min readIntermediate

Time series operators and ARIMA

tsset, the L. F. D. operators, tsline, dfuller for unit roots, arima, and forecasting basics.

83%

Listen along

Read “Time series operators and ARIMA” aloud

Plays in your browser using on-device text-to-speech — nothing leaves the page.

Learning objectives

By the end of this module, you should be able to:

  • 01Declare a time variable with tsset and use the L., F., D. operators for lag, lead, and difference
  • 02Test for unit roots with the Augmented Dickey-Fuller test (dfuller)
  • 03Fit ARIMA models and generate forecasts
  • 04Plot time series with tsline and recognise stationarity issues visually

Time series in Stata: tsset declares the time variable, time-series operators (L. F. D.) reference past, future, and difference values, dfuller tests for unit roots, and arima fits the standard time-series models.

tsset

stata
tsset month, monthly
tsset year, yearly

Lag, lead, difference operators

stata
generate lag1 = L.cpi // 1-period lag
generate lag12 = L12.cpi // 12-period lag
generate lead1 = F.cpi // 1-period lead
generate diff1 = D.cpi // first difference
generate diff12 = D12.cpi // 12-period difference (year-over-year change)
generate growth = (cpi / L12.cpi - 1) * 100 // YoY % change

tsline — time series plotting

stata
tsline cpi
tsline cpi, name(g1)
tsline cpi lending_rate, name(g2)

Unit roots: dfuller

stata
dfuller cpi // Augmented Dickey-Fuller, no constant
dfuller cpi, trend // with trend
dfuller cpi, lags(4) // 4 lagged differences
* Reject H0 (unit root) → variable is stationary
dfuller D.cpi // test in first differences

ARIMA

stata
arima cpi, arima(1, 1, 1) // ARIMA(p, d, q): AR=1, integrated=1, MA=1
estat ic // information criteria for model selection

Forecasting

stata
arima cpi, arima(1, 1, 1)
predict yhat
predict resid, residuals
forecast list // built-in forecast diagnostics

First-difference if non-stationary, then model

If dfuller fails to reject the unit root, take first differences (D.cpi) and re-test. Models on stationary data give valid inference; models on non-stationary data give spurious regressions.

Exercise

Compute the year-over-year growth rate of cpi.

Key takeaways

  • tsset month, monthly declares a monthly time series; daily/weekly/quarterly/yearly all supported
  • L.x is the lag; D.x is the first difference; D12.x is the 12-period difference (year-on-year)
  • dfuller H0 = unit root; failing to reject means non-stationary — take first differences and re-test
  • Modelling on non-stationary data produces spurious regressions — always check for stationarity first

Further reading

  1. 01

    Introduction to Time Series Using Stata (Revised Edition)

    Sean Becketti · Stata Press · 2020

  2. 02

    Time Series Analysis

    James D. Hamilton · Princeton University Press · 1994The graduate-level reference.

  3. 03
Loading progress…
LeadAfrikPublic Economics Hub