এই বইটি এখনো বাংলা ভাষায় পাওয়া যায় না। সংস্করণ: English।
University Economics — Year 2 · স্নাতক দ্বিতীয় বর্ষ
34Time Series: A First Course
Most macroeconomic data are time series: one country, observed quarter after quarter. Each observation resembles the one before it, the samples are short, and many series wander without returning to a fixed level. The regression methods of the last four chapters assumed independent observations; this chapter shows what changes when they are not. The chart shows the main danger: two series that have nothing to do with each other.
Each walk adds an independent random step to its previous value; the two were drawn separately. Yet the regression of B on A has an of 0.55 and a statistic of . The pair was picked to make the point; the chapter’s first listing measures how often such a result appears by chance.
You already know
From the Year 1 volume: logarithms and growth rates, the OLS estimator, , tests and confidence intervals. From Chapter 31: robust standard errors and the size of a test. From Chapter 28: detrending and the cyclical component.
34.1 Trend and season
A series , , often has a trend, a slow, persistent movement such as the growth of real GDP, and a season, a pattern that repeats each year, such as retail sales that peak in December. Official statistics usually publish seasonally adjusted series, from which the season has been estimated and removed; the series used below are all seasonally adjusted. A trend is handled by taking logarithms and differences: is the growth rate in per cent, and four times it, for a quarterly series, the annualised rate. The deviation from a smooth trend was the business cycle of Chapter 28.
34.2 Autocorrelation
Definition 34.1 (Autocorrelation function)
The autocorrelation function of a series gives, for each lag , the correlation between the series and itself periods earlier. Its sample version is .
"""Sample autocorrelations of US inflation and unemployment, 1959-2009."""
import numpy as np
from econdata import sm_dataset
from statsmodels.tsa.stattools import acf
d = sm_dataset("macrodata")
for name in ("infl", "unemp"):
x = d[name].to_numpy()
r = acf(x, nlags=4)
xd = x - x.mean()
r1 = (xd[1:] @ xd[:-1]) / (xd @ xd) # lag 1 by hand
print(f"{name:6s} lags 1-4: {np.round(r[1:], 3)} lag 1 by hand {r1:.3f}")
print(f"band for white noise: +/- {1.96 / np.sqrt(len(d)):.3f}")
$ python acf.py
infl lags 1-4: [0.642 0.595 0.616 0.493] lag 1 by hand 0.642
unemp lags 1-4: [0.956 0.88 0.793 0.706] lag 1 by hand 0.956
band for white noise: +/- 0.138
Inflation has a first autocorrelation of 0.64, unemployment of 0.96, and both stay above the band for twelve quarters. A regression on such data has far fewer independent observations than its 203 quarters suggest.
34.3 Stationarity
Definition 34.2 (Weak stationarity)
A series is weakly stationary if its mean and variance do not depend on , and the covariance depends only on the lag .
Definition 34.3 (White noise)
A white noise is a series with mean zero, constant variance and no autocorrelation at any lag.
A stationary series returns to its mean; its past is informative about its future, but less and less so at longer horizons. A series with a trend is not stationary, nor is a random walk (Section 34.5). Least squares, its standard errors and its tests keep their usual large-sample behaviour when the series involved are stationary and their autocorrelations die out fast enough; they lose it when the series are not.
34.4 Autoregressive and moving-average models
Definition 34.4 (Autoregressive process)
An autoregressive process of order , AR(), is with white noise.
Definition 34.5 (Moving-average process)
A moving-average process of order , MA(), is with white noise.
Proposition 34.6 (Moments of an AR(1))
If with and stationary, then
Proof. Take expectations: , so . Take variances, using that is uncorrelated with (which depends only on earlier shocks): . Multiply by and take expectations: for , so and . ∎
A shock to an AR(1) decays geometrically: after periods a fraction remains, and half of it is gone after periods, the shock’s half-life. An MA(1) remembers one period only: and for (Exercise 10). An AR model is fitted by least squares of on its own lags.
"""AR(1) and AR(2) for US unemployment: least squares by hand, and AutoReg."""
import numpy as np
import statsmodels.api as sm
from econdata import sm_dataset
from statsmodels.tsa.ar_model import AutoReg
u = sm_dataset("macrodata").unemp.to_numpy()
ols1 = sm.OLS(u[1:], sm.add_constant(u[:-1])).fit()
ar1 = AutoReg(u, lags=1).fit()
print(f"AR(1) by OLS: c {ols1.params[0]:.4f}, phi {ols1.params[1]:.4f}")
print(f"AR(1) by AutoReg: c {ar1.params[0]:.4f}, phi {ar1.params[1]:.4f}")
c, phi = ols1.params
half_life = np.log(0.5) / np.log(phi)
print(f"implied mean {c / (1 - phi):.2f}; half-life {half_life:.1f} quarters")
X2 = sm.add_constant(np.column_stack([u[1:-1], u[:-2]]))
ols2 = sm.OLS(u[2:], X2).fit()
ar2 = AutoReg(u, lags=2).fit()
print(f"AR(2) by OLS: {np.round(ols2.params, 4)}")
print(f"AR(2) by AutoReg: {np.round(ar2.params, 4)}")
print(f"t of the second lag {ols2.tvalues[2]:.2f}")
$ python ar_fit.py
AR(1) by OLS: c 0.0889, phi 0.9880
AR(1) by AutoReg: c 0.0889, phi 0.9880
implied mean 7.44; half-life 57.6 quarters
AR(2) by OLS: [ 0.2487 1.6394 -0.68 ]
AR(2) by AutoReg: [ 0.2487 1.6394 -0.68 ]
t of the second lag -12.90
The AR(1) coefficient of 0.988 implies a half-life of 58 quarters, more than fourteen years, which is not a credible description of how unemployment recovers from a recession. The AR(2) tells a different story: a rise in unemployment is followed by further rises (), then a fall (, ), the hump of a recession and its recovery. A coefficient this close to one also raises the question of the next section.
34.5 Unit roots and spurious regression
Definition 34.7 (Unit root)
A series has a unit root if it is an autoregression whose coefficients sum to one; the simplest case is the random walk . Its shocks never decay, and its variance grows with .
Definition 34.8 (Spurious regression)
A spurious regression is a regression between series with unit roots that shows a large and significant statistics although the series are unrelated.
"""Spurious regression: independent random walks, regressed on each other."""
import numpy as np
import statsmodels.api as sm
rng = np.random.default_rng(34)
n, reps = 200, 2000
levels = diffs = 0
r2 = []
for _ in range(reps):
x = rng.standard_normal(n).cumsum()
y = rng.standard_normal(n).cumsum() # independent of x
fit = sm.OLS(y, sm.add_constant(x)).fit()
levels += abs(fit.tvalues[1]) > 1.96
r2.append(fit.rsquared)
fit_d = sm.OLS(np.diff(y), sm.add_constant(np.diff(x))).fit()
diffs += abs(fit_d.tvalues[1]) > 1.96
print(f"levels: |t| > 1.96 in {levels / reps:.3f} of samples")
print(f" median R2 {np.median(r2):.3f}")
print(f"differences: |t| > 1.96 in {diffs / reps:.3f} of samples")
$ python random_walks.py
levels: |t| > 1.96 in 0.839 of samples
median R2 0.174
differences: |t| > 1.96 in 0.059 of samples
In levels the test rejects the true hypothesis of no relation in 84 per cent of the samples, and the median is 0.17. The residuals of such a regression are themselves a random walk, and the formulas for the standard errors assume they are not. In differences, where each series is white noise, the test rejects 5.9 per cent of the time, as it should.
Definition 34.9 (Dickey–Fuller test)
The Dickey–Fuller test tests the null hypothesis of a unit root by regressing on a constant (and possibly a trend), , and lags of ; the statistic is the ratio of the coefficient on , compared with critical values derived under the unit-root null, which are more negative than those of the normal distribution.
Under a unit root the ratio does not follow the usual distribution: the 5 per cent critical value is about with a constant and with a constant and a trend, against for a one-sided normal test. The version with lags of is called augmented.
"""Dickey-Fuller tests: log real GDP (with a trend) and its growth rate."""
import numpy as np
from econdata import sm_dataset
from statsmodels.tsa.stattools import adfuller
d = sm_dataset("macrodata")
lgdp = np.log(d.realgdp.to_numpy())
growth = 400 * np.diff(lgdp) # annualised, per cent
for name, x, trend in (("log real GDP", lgdp, "ct"), ("GDP growth", growth, "c")):
stat, p, lags, nobs, crit, _ = adfuller(
x, regression=trend, autolag="AIC", result_object=False
)
print(f"{name:13s} ADF {stat:6.2f}, 5 % critical value {crit['5%']:.2f},"
f" p-value {p:.3f}, lags {lags}") # fmt: skip
$ python adf.py
log real GDP ADF -2.38, 5 % critical value -3.43, p-value 0.389, lags 2
GDP growth ADF -6.97, 5 % critical value -2.88, p-value 0.000, lags 1
Log real GDP gives , short of the critical value of : the data cannot reject a unit root around a trend. Its growth rate gives , far beyond . The test has low power: it often fails to reject a unit root in series that are stationary but persistent, and 50 years of quarterly data rarely settle the question. The practical lesson is narrower: a regression in levels of persistent series needs a reason to be believed, and regressions in growth rates are the safer default.
34.6 Distributed lags
Definition 34.10 (Distributed-lag model)
A distributed-lag model relates to current and past values of a regressor: .
Definition 34.11 (Dynamic multiplier)
In a distributed-lag model the dynamic multiplier at horizon is , the effect on of a one-unit change in alone; the long-run multiplier is , the effect of a permanent one-unit change in .
If a rise of one point in a tax rate lowers sales by 0.2 per cent in the same quarter, 0.3 in the next and 0.1 in the one after, the dynamic multipliers are , and , and the long-run effect of a permanent rise is per cent. The coefficients have a causal reading only if is unrelated to the error at all leads and lags, the conditions of Chapter 33 stated in time; and since is usually autocorrelated, the standard errors need the correction of Section 34.9.
34.7 Forecasting and how to score it
Definition 34.12 (Out-of-sample forecast)
An out-of-sample forecast of is made with a model fitted only on data available at date ; a pseudo out-of-sample exercise repeats this for each in a past period, refitting each time, and compares the forecasts with what happened.
Definition 34.13 (Root mean squared forecast error)
The root mean squared forecast error of forecasts is over the forecasts made.
A model’s fit within its own sample flatters it: it was chosen to fit those data. The honest test is out of sample, against a simple benchmark. For inflation the benchmark is the random walk: inflation over the next four quarters equals inflation over the past four.
"""Four-quarter inflation forecasts, 1986-2009: a regression against a random walk."""
import numpy as np
from econdata import sm_dataset
d = sm_dataset("macrodata")
t = (d.year + (d.quarter - 1) / 4).to_numpy()
p = np.log(d.cpi.to_numpy())
pi4 = np.full(len(d), np.nan)
pi4[4:] = 100 * (p[4:] - p[:-4]) # inflation over the past four quarters
err_ar, err_rw = [], []
for i in range(len(d) - 4):
if t[i] < 1985:
continue
j = np.arange(8, i - 3) # past pairs (j -> j + 4) known at quarter i
A = np.column_stack([np.ones(len(j)), pi4[j], pi4[j - 4]])
b = np.linalg.lstsq(A, pi4[j + 4], rcond=None)[0] # refitted every quarter
forecast = b @ [1, pi4[i], pi4[i - 4]]
err_ar.append(pi4[i + 4] - forecast)
err_rw.append(pi4[i + 4] - pi4[i]) # random walk: no change
for name, e in (("regression", err_ar), ("random walk", err_rw)):
e = np.array(e)
print(f"{name:12s} RMSE {np.sqrt(np.mean(e**2)):.3f}, mean error {e.mean():.3f}")
print(f"forecasts: {len(err_ar)}")
$ python forecast.py
regression RMSE 1.772, mean error -0.722
random walk RMSE 1.624, mean error -0.178
forecasts: 95
Over 95 forecasts the regression misses by 1.77 points in root mean square, the random walk by 1.62. The regression forecasts lie above the outcome on average (a mean error of ): fitted on data that include the high inflation of the 1970s, it keeps predicting a return toward a higher mean that did not come. Both miss the fall of 2009 by several points.
On the record — Inflation forecasts against a random walk
Atkeson and Ohanian (2001) compared three sets of inflation forecasts built on the relation between inflation and unemployment (a textbook model, two models of a type then common in research, and the forecasts of the Federal Reserve Board) with the naive forecast that inflation over the next year equals inflation over the past year, over the previous 15 years. None was more accurate than the naive forecast, and they predicted the direction of the change in inflation no better than a coin flip.
34.8 What Granger causality does and does not mean
Definition 34.14 (Granger causality)
A series Granger-causes a series if past values of help predict given past values of ; the test is an test that the coefficients on the lags of are all zero in a regression of on lags of and of .
"""Granger causality between money growth and inflation, US 1959-2009."""
import numpy as np
import pandas as pd
from econdata import sm_dataset
from statsmodels.tsa.stattools import grangercausalitytests
d = sm_dataset("macrodata")
m = 400 * np.diff(np.log(d.m1.to_numpy())) # M1 growth, annualised
infl = d.infl.to_numpy()[1:]
data = pd.DataFrame({"infl": infl, "money": m})
for target, cause in (("infl", "money"), ("money", "infl")):
res = grangercausalitytests(data[[target, cause]], maxlag=4)
F, p = res[4][0]["ssr_ftest"][:2]
print(f"does {cause} help predict {target}? F {F:.2f}, p-value {p:.3f}")
$ python granger.py
does money help predict infl? F 2.15, p-value 0.076
does infl help predict money? F 1.47, p-value 0.213
With four quarterly lags, money growth does not help predict inflation at the 5 per cent level (), nor inflation money growth (). The name promises more than the test delivers. Granger causality is about prediction, not about effects in the sense of Chapter 33: a variable that responds to expectations of the future, such as an asset price, can predict an outcome it does not cause, and a policy that offsets shocks can cause an outcome while failing to predict it. The test answers a forecasting question; for that question it is the right one.
34.9 Serial correlation in regressions
When the errors of a regression are autocorrelated, least squares remains unbiased if the regressors are unrelated to the errors, but the classical and the heteroskedasticity-robust standard errors are both wrong: they ignore that neighbouring errors move together. Overlapping data make the problem certain: the change in inflation over the next four quarters, measured each quarter, shares three quarters with its neighbour.
Definition 34.15 (HAC standard error)
A HAC standard error (heteroskedasticity and autocorrelation consistent) replaces the middle term of the sandwich formula by with weights ; this is the Newey–West estimator.
"""Overlapping four-quarter changes: classical and Newey-West standard errors."""
import numpy as np
import statsmodels.api as sm
from econdata import sm_dataset
d = sm_dataset("macrodata")
p = np.log(d.cpi.to_numpy())
pi4 = 100 * (p[4:] - p[:-4]) # four-quarter inflation from 1960Q1
u = d.unemp.to_numpy()[4:]
change = pi4[4:] - pi4[:-4] # change in inflation over the next four quarters
X = sm.add_constant(u[:-4]) # unemployment at the start
classical = sm.OLS(change, X).fit()
hac = sm.OLS(change, X).fit(cov_type="HAC", cov_kwds={"maxlags": 4})
res = classical.resid
r1 = (res[1:] @ res[:-1]) / (res @ res)
print(f"slope on unemployment {classical.params[1]:.3f}")
print(f"classical s.e. {classical.bse[1]:.3f}, Newey-West s.e. {hac.bse[1]:.3f}")
print(f"first autocorrelation of the residuals {r1:.3f}")
$ python hac.py
slope on unemployment -0.286
classical s.e. 0.095, Newey-West s.e. 0.151
first autocorrelation of the residuals 0.777
The slope is : higher unemployment is followed by falling inflation. The residuals have a first autocorrelation of 0.78, and the Newey–West standard error, 0.151, is 1.6 times the classical 0.095. The statistic falls from to : significant at 5 per cent with the wrong standard error, not quite with the right one.
Model — AR(1) model
Assumes. with and white-noise shocks: the series returns to a fixed mean, and a shock decays by the factor each period.
Predicts. Autocorrelations ; a forecast that moves from the last value toward the mean ; forecast intervals that widen with the horizon toward the series’ own spread.
Tested. US unemployment fits an AR(1) with , a half-life of 58 quarters at odds with its recoveries; an AR(2) fits its hump far better. Inflation forecasts from regressions on past inflation did no better than a random walk from 1986 to 2009, as Atkeson and Ohanian (2001) found for richer models.
Breaks. When the mean shifts (inflation in the 1970s and after 1985) or the series has a unit root, the fitted and the implied mean describe the sample, not the future; short samples cannot tell a large from a unit root.
34.10 Exercises
Exercise 34.1 ★
Read the opening chart. If you knew nothing of how the walks were made, what would the regression suggest? Why is the suggestion wrong?
Solution
Solution of Exercise 34.1.
A strong negative relation: , . It is wrong because the walks are independent by construction. Both wander far from their start, and two wandering series drift in some direction relative to each other in any sample; the statistic, computed as if the residuals were independent, treats this drift as evidence.
Exercise 34.2 ★
From the ACF chart, give the first and the twelfth autocorrelations of inflation and of unemployment, and the band. Which series is more persistent?
Solution
Solution of Exercise 34.2.
Inflation 0.642 at lag 1 and 0.238 at lag 12; unemployment 0.956 and 0.260; band . Unemployment is far more persistent from quarter to quarter; after three years the two have similar autocorrelations, both still outside the band.
Exercise 34.3 ★
A distributed-lag model has , , , . Give the dynamic multipliers and the long-run multiplier.
Solution
Solution of Exercise 34.3.
Dynamic multipliers 0.4, 0.3, 0.2 and 0.1 at horizons 0 to 3; long-run multiplier .
Exercise 34.4 ★
A share price predicts next quarter’s GDP. Does it Granger-cause GDP? Does it cause GDP?
Solution
Solution of Exercise 34.4.
It Granger-causes GDP if it helps predict GDP given GDP’s own past, which is what the statement says. That does not mean it causes GDP: share prices respond to expected profits, so they move before the GDP changes that investors foresee, without producing them.
Exercise 34.5 ★★
For an AR(1) with , , : give the mean, the variance, the first three autocorrelations and the half-life of a shock.
Solution
Solution of Exercise 34.5.
Mean ; variance ; autocorrelations 0.5, 0.25, 0.125; half-life period.
Exercise 34.6 ★★
From the AR(1) output for unemployment, compute the implied mean and the half-life. Compare the implied mean with the sample mean of the unemployment rate (5.9 per cent). What explains the gap?
Solution
Solution of Exercise 34.6.
Implied mean per cent; half-life quarters. The sample mean is 5.9. With so close to one, is very sensitive to small errors in : its delta-method standard error is 3.0 points, so the gap is well within the estimate’s uncertainty. The AR(1) is also the wrong shape (the AR(2) fits much better), which biases its toward one.
Exercise 34.7 ★★
(D) Add the unemployment rate at the forecast date to the forecasting regression of the listing and repeat the exercise. Does the root mean squared error fall?
Solution
Solution of Exercise 34.7.
Root mean squared errors: 1.772 without unemployment, 1.775 with it, 1.624 for the random walk. Adding unemployment does not help; the random walk still wins, as Atkeson and Ohanian (2001) found with richer models over a similar period.
Exercise 34.8 ★★
Why does the regression in differences of the random-walk listing reject at the nominal rate while the regression in levels does not?
Solution
Solution of Exercise 34.8.
In differences both series are independent white noise: the regression’s errors are white noise, independent of the regressor, and the usual statistic has its usual distribution, so it rejects 5.9 per cent of the time, close to 5. In levels the errors are a random walk, so the classical standard error is far too small and the statistic does not settle down as the sample grows.
Exercise 34.9 ★★
From the HAC output, compute the statistic of the slope with each standard error. Which conclusion changes at the 5 per cent level, and which does not?
Solution
Solution of Exercise 34.9.
with the classical error and with Newey–West. At the 5 per cent level the classical test rejects a zero slope and the Newey–West test does not; at 10 per cent both reject. The estimate itself is the same.
Exercise 34.10 ★★★
For the MA(1) , derive the variance and the autocorrelations. Which value of gives the largest first autocorrelation?
Solution
Solution of Exercise 34.10.
; , so ; at lags 2 and more the two terms share no shock, so . The derivative of is , zero at , where : an MA(1) can never have a first autocorrelation above one half.
Exercise 34.11 ★★★
For a random walk starting at , show that and that the correlation of with is . Why does this rule out stationarity?
Solution
Solution of Exercise 34.11.
, a sum of independent shocks, so . , since the later shocks are independent of ; the correlation is . The variance and the correlation depend on , which weak stationarity forbids.
Exercise 34.12 ★★★
For an AR(1) with known , and , derive the -step forecast and its error variance. What do they tend to as grows?
Solution
Solution of Exercise 34.12.
With , . So , and the error variance is . As grows the forecast tends to the mean and the error variance to the series’ own variance : far enough ahead, knowing does not help.
34.11 Problem: Brenland’s inflation
Problem 34.1
Weekend problem — Brenland’s inflation: growth rates and autocorrelation, an AR(1), a unit-root test, and a two-year forecast
Brenland’s consumer price index for 2000–2025 is in the country’s national accounts (accounts, column cpi, 2015 = 100). Use annual inflation , 2001–2025.
Part I — Growth rates and autocorrelation.
- How many observations of are there?
- Give the mean and standard deviation of inflation.
- In which year was inflation highest, and how high?
- Give inflation in 2025.
- Give the first sample autocorrelation.
- Is it outside the 95 per cent band for white noise?
Part II — An AR(1).
- Fit by least squares: give and .
- Give the standard error of and its statistic against zero.
- Give the implied mean and compare it with the sample mean.
- Give the half-life of an inflation shock.
- Give the standard deviation of the residuals.
- What does the AR(1) say about the 2022 surge?
Part III — A unit-root test.
- Write the Dickey–Fuller regression with a constant and no lags.
- Give the statistic.
- Give the 5 per cent critical value for this sample.
- Is a unit root rejected at 5 per cent? At 10 per cent?
- How can fail to reject ?
- What does this mean for Part IV?
Part IV — A forecast and its interval.
- Forecast inflation for 2026.
- Forecast inflation for 2027.
- Give the standard error of each forecast, ignoring the uncertainty in and .
- Give the 95 per cent interval for 2027.
- Why is the 2027 interval wider than the 2026 one, and what width does it tend to?
- What would a random-walk forecast give for 2027?
- State the result: the AR(1) persistence, the half-life of an inflation shock, and the two-year forecast with its interval.
Solution
Solution of Problem 34.1.
Part I. 1. 25 (2001–2025). 2. Mean 2.69 per cent, standard deviation 1.71. 3. 2022, at 9.70 per cent. 4. 2.47 per cent. 5. 0.48. 6. Yes: the band is . Part II. 7. , . 8. Standard error 0.186; . 9. , close to the sample mean of 2.69. 10. years: about a year. 11. 1.56 points. 12. The 2022 residual is 6.51 points, 4.2 residual standard deviations: an exceptional shock, which the AR(1) then expects to halve each year. Its forecasts for 2023 and 2024 (6.09 and 4.05) were close to the outcomes (5.49 and 3.71), a little above them. Part III. 13. with ; the null is . 14. . 15. (with 25 observations; at 10 per cent). 16. Not at 5 per cent; yes at 10 per cent (). 17. The statistic is : with 24 usable years the standard error is large, and under the null the statistic has a distribution shifted to the left, so even an estimate far below one is not far enough. The test has little power in so short a sample. 18. The AR(1) forecast assumes inflation returns to 2.7; if inflation has a unit root, it need not, and the intervals of Part IV are too narrow. The test cannot rule this out, so the forecast is conditional on stationarity. Part IV. 19. per cent. 20. per cent. 21. 1.56 for 2026; for 2027. 22. : from to 6.06 per cent. 23. Two years ahead, two shocks are unknown. As the horizon grows the standard error tends to , a half-width of 3.5 points. 24. 2.47 per cent, the last observation, with an error that keeps growing with the horizon. 25. Brenland’s inflation has an AR(1) persistence of 0.48: half of an inflation shock is gone in about a year (0.96 years), and the two-year-ahead forecast for 2027 is 2.65 per cent, with a 95 per cent interval from to 6.06 — on the assumption, which 25 years of data cannot confirm, that inflation has no unit root.