AFE Lab 2
Unit Root tests and non-stationary time series
This set of exercises are adapted from Example 3.2 of Mills and Markellos (2008). We shall be using the same data as in Lab 1 ‘FTSE.csv’. The learn- ing objective is to understand (a) the unit root tests and (b) the difference between a trend stationary and a difference stationary process. We shall be exploring different unit root tests both manually and using built in tests in both Stata and R software packages.
Task 0: Before the start of the Lab session
Using your skills developed so far or the do file, RScript file you have from Lab 1,
(a) Open RStudio, open a new script file and save it in the same folder as in Lab 1. Set the working directory, load the data file ‘FTSE.csv’. Check the data structure with the command ‘str’. If the date variable is character, follow Lab 1 to format it to a numeric date variable. Convert the data as an xts object: FT xts. Generate the lags and difference variables as in Lab 1.
(b) Open Stata, create and save a do file and a log file, change working directory, and load the data file ‘FTSE.csv’. Check the data with the commands ‘des’, ‘sum’ and format the date variable as in Lab 1. Declare time series using the formatted date variable.
Task 1: The Dickey-Fuller (DF) and Augmented Dickey-Fuller (ADF) tests of unit root
(a) Plot a time series line graph to check the data. Do you think there is a trend in the variable?
Stata: tsline ftse R: plot(FT_xts)
(b) Let us run a simple DF test using the built in commands in Stata first. 1
dfuller ftse
– Write down the equation for the above DF test, the null and the alternative hypothesis.
– Does the series have a unit root?
(c) Let us run the same test using the built in commands in R and check if our conclusion from Stata matches. Install the package urca and run the following code:
install.packages(urca)
library(urca)
# DF test with intercept (drift), no lags (DF), no trend
df<-ur.df(FT_xts, type="drift", lags=0)
summary(df)
(d) The ADF test includes lags of the dependent variable to augment the DF test and controls for any serial correlation. To obtain a reliable test result, it is important to include enough lags. R with urca package allows you to select the optimum lags by using either AIC or BIC criteria. Let us check that first with the three specifications of the ADF test.
ADF_none<-ur.df(FT_xts, type="none",selectlags="AIC")
summary(ADF_none)
ADF_drift<-ur.df(FT_xts, type="drift",selectlags="AIC")
summary(ADF_drift)
ADF_trend<-ur.df(FT_xts, type="trend",selectlags="AIC")
summary(ADF_trend)
How many lags are we using based on AIC criteria? Is this the same for all three versions of the ADF test? Which model best represents the data? Does the series have a unit root?
(e) Now let us check the same using Stata. Let us use the optimum lags we obtained from R and substitute below in lags().
dfuller ftse, lags() noconstant
dfuller ftse, lags()
dfuller ftse, lags() trend
2
(f) Finally, let us use the regressions to manually perform the ADF test. Run the following code in R for a model with trend and intercept. Before running the OLS regression, you need to generate the lag and difference variables in R (you don’t need this step in Stata).
dfmodel3 <- lm(DFT ̃c(1:length(LFT)) + LFT + LDFT, data = data1)
summary(dfmodel3)
In Stata:
gen trend=_n
reg D.ftse trend L.ftse L.D.ftse
Task 2: Trend Stationary (TS) versus Difference Stationary (DS) process
Sometimes, it is hard to distinguish between a TS process and a DS process. We would like to check if in case the series is TS rather than having a unit root (DS).
(a) Following your estimates in Task 1 (e), do you reject the null hypothesis that the series is non-stationary? If the series is non-stationary, first assume the series to be TS and run the following regression (1) (using either Stata or R, you should choose the value of r based on your Task 1 model specification), and test the hypothesis that H0 : β1 = 0 against HA : β1 ̸= 0. Comment if the series is TS or not.
r
∆yt =β0 +β1t+φi∆yt−i +et (1)
i=1
(b) If the series is not TS based on (a) above, consider the ADF test with drift but without trend from part (c) or (d) in Task 1. Do you reject the null that the series is non-stationary? If the series is non-stationary, estimate the equation (2) below and test the hypothesis H0 : β0 = 0 against HA : β0 ̸= 0. Comment if the series is TS or DS.
∆yt = β0 + et (2) 3
(c) Comment on the order of integration of the series. Hint: if the series is TS, it is stationary after controlling for trend, and so I(0). On the other hand, if a series is DS, you need to difference the series to make it stationary. Check with the first difference series if that is stationary or not to comment on the order of integration. R code:
DFT<-na.omit(DFT)
dy_none<-ur.df(DFT, type="none",selectlags="AIC")
summary(dy_none)
Task 3 (optional): The Phillips-Perron, KPSS and Zivot-Andrew tests of unit root
(a) The Phillips-Perron test (Non-parametric, corrects for heteroscedastic- ity and serial correlation). Run the Phillips-Perron test with trend and comment on the results.
Stata: pperron ftse, trend
R: p_trend<-ur.pp(FT, type="Z-tau", model="trend", lags="short")
summary(p_trend)
(b) The KPSS test (tests against the null of stationarity, used to identify fractional integration). Run the KPSS test and comment on the results.
Stata: kpss ftse
R: k_test<-ur.kpss(FT_xts, type="tau", lags="short")
summary(k_test)
(c) The Zivot-Andrews test (unit root test allowing for a single break in intercept and/or trend with a null hypothesis: the series has a unit root with structural break; alternative hypothesis: the series is stationary with a break). Run the KPSS test with both trend and intercept, and comment on the results.
Stata: zandrews ftse
R: z_trend<-ur.za(FT_xts, model="both", lag=1)
summary(z_trend)
4
References
Mills, T. C. and Markellos, R. N. (2008). The econometric modelling of financial time series. Cambridge University Press.
5