set echo off set messages off # Illustration of spurious regression nulldata 100 # define the data as time series for graphing setobs 1 1 --special-time-series scalar type1a = 0 scalar type1b = 0 scalar N = 1000 matrix R2 = zeros(N,2) matrix tmat = zeros(N,2) loop i=1..N --quiet series e = normal() series y = cum(e) series a = normal() series x = cum(a) # A: regression of normal y on normal x ols e 0 a --quiet scalar tstat = $coeff[2]/$stderr[2] type1a += (abs(tstat) > 2.0) R2[i,1] = $rsq tmat[i,1] = tstat # B: regression of unit-root y on unit-root x ols y 0 x --quiet scalar tstat = $coeff[2]/$stderr[2] type1b += (abs(tstat) > 1.96) R2[i,2] = $rsq tmat[i,2] = tstat endloop printf "A: Instances of |t| > 1.96: %.1f percent\n", 100*type1a/N printf "B: Instances of |t| > 1.96: %.1f percent\n", 100*type1b/N