/* Introduction to Time Series Analysis, DG ECFIN Laura Mayoral November 2021 */ /******************Univariate Non Stationary models ************** This file simulates some non statinary processes and runs unit root tests ***********************************************************************/ *0. Simulate some data. clear all set seed 2021 local T = 800 set obs `T' gen time = _n label var time "Time" tsset time gen eps = rnormal(0,5) /*Random walk*/ gen yrw = eps in 1 replace yrw = l.yrw + eps in 2/l /*Random walk with drift*/ gen yrwd1 = .5+ eps in 1 replace yrwd1 = .5 + l.yrwd1 + eps in 2/l /*Random walk with drift*/ gen yrwd2 = 1 + eps in 1 replace yrwd2 = 1 + l.yrwd2 + eps in 2/l /*Stationary around a time trend model*/ gen yt = 0.5 + 0.5*time + eps in 1 replace yt = 0.5 + 0.5*time +0.8*l.yt+ eps in 2/l drop in 1/50 tsline yrw yrwd1, title("Stochastic trend") /// legend(label(1 "Random walk") /// label(2 "Random walk with drift")) tsline yt yrwd2, /// legend(label(1 "Deterministic time trend") /// label(2 "Random walk with drift")) /// title("Stochastic and deterministic trend") *1. Run unit root tests *Price deflator and inflation *(inflation is the same series we've used in the VAR example') cd "/Users/lauramayoral/Dropbox/docum_dropbox/clases/ECFIN_time series/STATA/files" use quarterly, clear gen log_price=log(deflator) generate inflation = 400 * log(deflator/L.deflator) tsset tsline inflation deflator ac inflation ac log_price ***************************************************************************************** * First generation of unit root tests ***************************************************************************************** *ADF test, always with constant and trend, correct for autocorrelation of the residuals using lags of the dep. variable dfuller log_price, trend lags(4) reg dfuller inflation, trend lags(4) reg *Phillips Perron: You can also correct for autocorrelation in the residuals using the non-parametric Phillips-perron correction pperron log_price, trend reg pperron inflation, trend reg ************************************************************ ***************************************************************************************** * Second generation of unit root tests: MUCH BETTER! ***************************************************************************************** *Better power and better size properties. *Lags are selected using MAIC of SIC *1) by default a trend is always included; ers: interpolated critical values dfgls log_price , maxlag(8) ers ***************************************************************************************** * STATIONARITY TESTS: KPSS ***************************************************************************************** *Install the module to apply KPSS test ssc install kpss *we reject that inflation is I(0)!! kpss inflation, maxlag(8) trend kpss inflation, maxlag(8) notrend ************* ************************************************************************* /* Fit an Arima process for log_price *************************************************************************/ *we need to go through the 3 steps again 1) identification, 2) estimation and diagnostic checking. *The difference now: introduce in 1) formal stationary tests arima log_price, arima(2,1,2) estat ic