University
Teaching materials · Time series econometrics · Undergraduate

Typed lecture notes:the first two weeks of time series, in full prose

From ECON30401 Time Series Econometrics, University of Manchester (third-year undergraduate).

Full typed lecture notes covering the first two weeks of an undergraduate time-series course, the prose companion to the slide decks, with every argument written out.

Slides compress; these notes explain. Written as continuous prose, they motivate time-series econometrics from familiar macro and finance variables (disposable income, interest rates), then develop the framework, processes, stationarity, white noise, dependence, with every derivation and piece of intuition written out, not bulleted.

What these materials cover

Download

Free to download and use for personal study. Written for my own university teaching; shared here as evidence of teaching style and depth.

Typed lecture notes: weeks 1–2 (PDF) TeX source (week 1, postgraduate edition) (.tex)

Six time series, and the code to draw them

Each chart in the opening chapter of the notes shows one feature a time-series model has to handle: forecast uncertainty that grows with the horizon, returns that are hard to predict but whose volatility changes, a smooth trend, strong persistence, a seasonal pattern, and a mean that shifts over time. All six use free data. The code below draws them, so you can change the dates or swap in another series and check whether the same features appear. The charts here come from the Python script; the R, Stata and EViews scripts take the same steps.

UK CPI inflation to August 2016 with an AR(1) forecast fan
Figure 1.2. UK CPI inflation to August 2016, then a fan of forecasts from an AR(1) fitted to the monthly data since 1989. The bands hold 30%, 60% and 90% of outcomes under the model.
Daily FTSE 100 log returns, 1991 to 1998
Figure 1.3. Daily FTSE 100 returns: centred on zero, hard to predict, with calm and volatile spells.
US population at each census, 1790 to 1990
Figure 1.4. US population at each census: a smooth curve, close to quadratic in time.
UK unemployment rate, monthly, 1971 to 2026
Figure 1.5. UK unemployment rate: long swings, so this month is a strong guide to next month.
UK retail sales, not seasonally adjusted, 2010 to 2019
Figure 1.6. UK retail sales before seasonal adjustment: a December peak every year.
UK Bank Rate, 1987 to 2017
Figure 1.7. UK Bank Rate: 10% to 15% around 1990, 0.5% from 2009, so its mean has not stayed fixed.

The data

ONS series are used under the Open Government Licence v3.0. The forecast fan is a simple AR(1) fitted by least squares; Section 2 of the notes explains the model and Lecture 4 the forecasts.

The code

# Time series examples: six charts from freely available data
# Dr Nicky Grant, drnickygrant.com. Companion to the ECON30401 lecture notes, weeks 1 and 2.
# Needs: pandas, numpy, matplotlib, scipy   (pip install pandas numpy matplotlib scipy)
import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.stats import norm

# Clean copies of each series, with their sources, are kept on the site.
BASE = os.environ.get("TS_DATA", "https://www.drnickygrant.com/teaching/data/")
OUT = os.environ.get("TS_OUT", ".")
plt.rcParams.update({"font.family": "DejaVu Serif", "font.size": 11,
                     "axes.spines.top": False, "axes.spines.right": False})


def monthly(file):
    """Read a month,value file and index it by month."""
    d = pd.read_csv(BASE + file)
    d.index = pd.PeriodIndex(d["month"], freq="M").to_timestamp()
    return d.iloc[:, 1]


def save(fig, name):
    fig.tight_layout()
    fig.savefig(os.path.join(OUT, name), dpi=200)
    plt.close(fig)


# 1. UK CPI inflation to August 2016 with a fan of AR(1) forecasts (ONS series D7G7)
cpi = monthly("uk-cpi-inflation-d7g7.csv")
y = cpi[:"2016-08"].to_numpy()
X = np.column_stack([np.ones(len(y) - 1), y[:-1]])
(c, phi), *_ = np.linalg.lstsq(X, y[1:], rcond=None)      # OLS of y_t on 1 and y_{t-1}
resid = y[1:] - X @ np.array([c, phi])
sigma = np.sqrt(resid @ resid / (len(resid) - 2))
H = 36                                                      # forecast three years ahead
mean, var, f, se = y[-1], 0.0, [], []
for h in range(H):
    mean = c + phi * mean                                   # E[Y_{T+h} | Y_T]
    var = sigma**2 + phi**2 * var                           # forecast-error variance
    f.append(mean); se.append(np.sqrt(var))
f, se = np.array(f), np.array(se)
months = pd.date_range("2016-08-01", periods=H + 1, freq="MS")
fig, ax = plt.subplots(figsize=(6.2, 4.6))
hist = cpi["2012-01":"2016-08"]
ax.plot(hist.index, hist, color="#b22222", lw=1.6)
for share, colour in [(0.90, "#f6c7b6"), (0.60, "#ef9a84"), (0.30, "#e06650")]:
    z = norm.ppf(0.5 + share / 2)
    ax.fill_between(months, np.r_[y[-1], f - z * se], np.r_[y[-1], f + z * se], color=colour, lw=0)
ax.axvspan(months[0], months[-1], color="0.93", zorder=-1)
ax.axhline(2, color="0.4", lw=0.8, ls="--")
ax.set_ylabel("% change on a year earlier")
ax.set_title("UK CPI inflation and an AR(1) forecast fan", fontsize=11)
save(fig, "fig1-uk-cpi-forecast-fan.png")

# 2. Daily FTSE 100 returns, 1991 to 1998 (R datasets package, EuStockMarkets)
ftse = pd.read_csv(BASE + "ftse-daily-1991-1998.csv")
ret = 100 * np.log(ftse["ftse"]).diff()
fig, ax = plt.subplots(figsize=(7.6, 3.0))
ax.plot(ftse["time"], ret, color="k", lw=0.5)
ax.axhline(0, color="0.5", lw=0.6)
ax.set_ylabel("log return, %")
ax.set_xlabel("Daily FTSE 100 returns, 1991 to 1998")
save(fig, "fig2-ftse-daily-returns.png")

# 3. US population at each census, 1790 to 1990 (US Census Bureau)
pop = pd.read_csv(BASE + "us-population-1790-1990.csv")
fig, ax = plt.subplots(figsize=(6.0, 4.2))
ax.plot(pop["year"], pop["population_millions"], "s-", color="k", ms=4, mfc="white", lw=0.9)
ax.set_ylabel("millions")
ax.set_xlabel("US population at each census, 1790 to 1990")
save(fig, "fig3-us-population.png")

# 4. UK unemployment rate, monthly (ONS series MGSX)
u = monthly("uk-unemployment-rate-mgsx.csv")
fig, ax = plt.subplots(figsize=(6.0, 4.2))
ax.plot(u.index, u, color="k", lw=0.9)
ax.set_ylabel("%")
ax.set_xlabel("UK unemployment rate, monthly")
save(fig, "fig4-uk-unemployment.png")

# 5. UK retail sales, value, not seasonally adjusted, 2010 to 2019 (ONS series J5AH)
r = monthly("uk-retail-sales-j5ah.csv")["2010-01":"2019-12"]
fig, ax = plt.subplots(figsize=(6.0, 4.2))
ax.plot(r.index, r, "s-", color="k", ms=2.5, mfc="white", lw=0.8)
ax.set_ylabel("index")
ax.set_xlabel("UK retail sales, monthly, not seasonally adjusted")
save(fig, "fig5-uk-retail-sales.png")

# 6. UK Bank Rate at the end of each month, 1987 to 2017 (Bank of England)
br = monthly("uk-bank-rate-1987-2017.csv")
fig, ax = plt.subplots(figsize=(6.0, 3.3))
ax.step(br.index, br, where="post", color="#0f5c5c", lw=1.4)
ax.set_ylabel("%")
ax.set_xlabel("UK Bank Rate, 1987 to 2017")
save(fig, "fig6-uk-bank-rate.png")
print("Six charts written to", os.path.abspath(OUT))

Download the Python script (time-series-charts.py)

What students say

“Nicky is an excellent econometrics tutor. He explains complex concepts clearly and makes them much easier to understand.”
Charles GardnerGoogle review
“I was completely lost in my economics class, and then I started working Nicky and he totally saved me. He was excellent at explaining the material and extremely accommodating to meet with me many times despite us being in different time zones! Highly recommend working with Nicky!”
Claire ChouGoogle review
“Nicky is a very good and thorough teacher. He has excellent knowledge of econometrics and takes the time to work through your questions. Highly recommended!”
ChrisEconometrics · 22/08
“Really great tutor! Encouraging, knowledgeable, friendly”
JedEconometrics · 09/02
“Very good lesson, Nicky is very helpful.”
ChrisEconometrics · 19/08
“Very helpful and clear.”
ClaireEconometrics · 22/01
“I gather it was very useful, thank you!”
ClaireEconometrics · 12/01
“Fantastic!”
JedEconometrics · 11/02

Who this is for

Students who learn better from prose than slides, and revision readers who want the full argument, not the compressed version.

Related free resources

One-to-one help

For help with this material, or the module it belongs to, see econometrics tuition or university economics tuition. The first consultation is free, with no obligation.

Free worked video lectures: @unientryTMUA on YouTube.

Related tuition

Need help with this topic?

For one-to-one help, choose the closest subject below or send a short enquiry with your level, topic and deadline.

Book consultation View all tutoring subjects

Free 30-min consultationNo obligation · reply within one business day
Book now