Time Series Econometrics

Coding Review

Setup: R Packages

For Time Series Estimation:

  • stats::arima() / stats::ar(): AR, MA, ARMA estimation
  • lmtest::coeftest(): Coefficient tests with robust SEs
  • sandwich::vcovHC(): Heteroskedasticity-consistent covariance
  • car::linearHypothesis(): Wald tests for joint hypotheses

Base R Tools:

  • acf(): Sample autocorrelation function (ACF)
  • pacf(): Partial autocorrelation function (PACF)
  • diff(): First (and higher-order) differences

Stationarity: What It Looks Like

Exercise 1: Stationary vs Non-Stationary Processes

Before fitting any models, it helps to develop intuition for what stationarity looks like in practice. We simulate three processes and compare them.

What to look for
  • White noise: Fluctuates around zero with roughly constant spread throughout. No memory.
  • AR(1), \(|\alpha_1| < 1\): Also fluctuates around a long-run mean, but with smoother, more persistent swings. After a large shock, the series gradually drifts back toward the mean, this is mean reversion.
  • Random walk: Wanders freely with no tendency to return to any level. The variance grows with time. Shocks accumulate forever (\(Y_t = Y_0 + \sum e_j\)), so the series can drift far from its starting point.

The visual contrast between the random walk and the AR(1) is exactly the difference between \(\alpha_1 = 1\) (unit root) and \(|\alpha_1| < 1\) (stationary). Testing which case applies to real data is one of the central problems in applied time series work.


The Autocorrelation Function (ACF)

Exercise 2: ACF Patterns for AR and MA Processes

The ACF is the primary diagnostic tool for identifying time series structure. MA(\(q\)) processes have ACFs that cut off sharply; AR processes have ACFs that decay gradually. Here we simulate both and compare.

Reading ACF and PACF plots
ACF PACF
MA(q) Cuts off after lag \(q\) Decays gradually
AR(p) Decays gradually Cuts off after lag \(p\)
ARMA Decays gradually Decays gradually

The dashed blue lines are approximate 95% confidence bands (\(\pm 1.96/\sqrt{n}\)). Bars that exceed these bounds are significantly different from zero. For MA(2), you should see significant bars at lags 1 and 2, and essentially nothing after that. For AR(1), you should see a smooth geometric decay in the ACF at rate \(\alpha_1^k = 0.8^k\).

The PACF is the correlation between \(Y_t\) and \(Y_{t-k}\) after removing the linear influence of \(Y_{t-1}, \ldots, Y_{t-k+1}\). For an AR(\(p\)), it cuts off sharply after lag \(p\), directly revealing the true order.


AR(1): Stationarity and the Role of \(\alpha_1\)

Exercise 3: How \(\alpha_1\) Shapes Persistence

The AR(1) coefficient \(\alpha_1\) governs everything: stationarity, mean reversion speed, variance, and the entire autocorrelation function. This exercise lets you compare three values and see the consequences directly.

Note

Fill in 0.3, 0.9, and 1.0 in the three simulate_ar1() calls.

y_low  <- simulate_ar1(0.3, e)
y_high <- simulate_ar1(0.9, e)
y_unit <- simulate_ar1(1.0, e)
Interpretation

The theoretical variance of a stationary AR(1) is \(\sigma^2/(1-\alpha_1^2)\). For \(\alpha_1 = 0.3\): \(1/0.91 \approx 1.1\). For \(\alpha_1 = 0.9\): \(1/0.19 \approx 5.3\). High persistence inflates variance dramatically; the series wanders more widely because shocks take much longer to dissipate.

The theoretical autocorrelation at lag \(k\) is \(\rho(k) = \alpha_1^k\). For \(\alpha_1 = 0.3\), \(\rho(5) = 0.3^5 \approx 0.002\) (essentially zero by lag 5). For \(\alpha_1 = 0.9\), \(\rho(5) = 0.9^5 \approx 0.59\) (still highly correlated at lag 5). This is why “near-unit-root” series like inflation or GDP are said to have long memory: shocks persist for many periods.

For \(\alpha_1 = 1\) (random walk), the variance grows without bound and the series never mean-reverts.


Impulse Response Functions

Exercise 4: Computing and Plotting an IRF

The impulse response function answers: if a shock \(e_t = 1\) hits today, what is the effect on \(Y_{t+j}\) for \(j = 0, 1, 2, \ldots\)? For AR models, the IRF coefficients \(b_j\) can be computed recursively from the estimated \(\alpha\) coefficients.

Note

alphas should be a vector. For an AR(1) with \(\alpha_1 = 0.3\), use alphas = c(0.3). For the random walk, alphas = c(1.0).

irf_03 <- irf_ar(alphas = c(0.3), horizon = 20)
irf_09 <- irf_ar(alphas = c(0.9), horizon = 20)
irf_rw <- irf_ar(alphas = c(1.0), horizon = 20)
Interpretation

For a stationary AR(1), \(b_j = \alpha_1^j\), so the IRF decays geometrically. The speed of decay is entirely determined by \(\alpha_1\):

  • \(\alpha_1 = 0.3\): After 3 periods, \(b_3 = 0.027\), the shock has essentially vanished.
  • \(\alpha_1 = 0.9\): After 10 periods, \(b_{10} = 0.35\), still substantial. After 20 periods, \(b_{20} = 0.12\).
  • \(\alpha_1 = 1\) (random walk): \(b_j = 1\) for all \(j\), shocks are permanent.

The AR(2) with \(\alpha_1 = 0.5\), \(\alpha_2 = -0.4\) produces an oscillating IRF because the characteristic roots are complex (since \(\alpha_1^2 + 4\alpha_2 = 0.25 - 1.6 < 0\)). The negative \(\alpha_2\) induces a reversal after one period, creating a dampened cycle, exactly the kind of pattern used to model business cycles.

In macroeconomics, the IRF is the key object of interest: “if the Fed raises rates by 25bp today, what happens to unemployment over the next 8 quarters?”


Estimating AR Models

Exercise 5: AR(p) Estimation and Inference

We now turn to fitting AR models using OLS, recall that AR(\(p\)) models are always identified and can be estimated by regressing \(Y_t\) on its lags. We use real-looking simulated data (an AR(2) with known parameters) and practice the full workflow: estimate, check residuals, test joint significance.

Note

The AR(2) model is \(Y_t = \alpha_0 + \alpha_1 Y_{t-1} + \alpha_2 Y_{t-2} + e_t\). Regress y on y_l1 and y_l2.

ar2_fit <- lm(y ~ y_l1 + y_l2, data = df)
coeftest(ar2_fit, vcov = vcovHC(ar2_fit, type = "HC3"))

Exercise 6: Joint Significance Test (Wald Test)

Now test whether the AR coefficients are jointly significant. Equivalently, whether the series has any predictable structure at all. This is the real-data analog of testing against a random walk or white noise null.

Note

linearHypothesis() takes a character vector of restrictions. Write them as "y_l1 = 0" and "y_l2 = 0".

linearHypothesis(
  ar2_fit,
  c("y_l1 = 0", "y_l2 = 0"),
  vcov = vcovHC(ar2_fit, type = "HC3")
)
Interpretation

The null hypothesis \(H_0: \alpha_1 = \alpha_2 = 0\) says that \(Y_t\) has no predictable component from its own past; it behaves like white noise. Rejecting this means at least one lag has predictive power.


Summary

Concept What it means How to check in R
Stationarity Mean, variance, ACF constant over time Plot the series; look for trending mean or growing variance
ACF cutoff MA(\(q\)): zero after lag \(q\) acf()
ACF decay AR(\(p\)): geometric decay acf()
PACF cutoff AR(\(p\)): zero after lag \(p\) pacf()
Persistence Governed by \(\alpha_1\) (AR(1)) Estimate and inspect; compare to 1
IRF Effect of shock at horizon \(j\) Recursive formula: \(b_j = \sum \alpha_k b_{j-k}\)
Identification AR always identified; MA may not be Use invertible root (\(|\theta| < 1\))
Joint significance All \(\alpha\) = 0? linearHypothesis() with robust SEs