MATLAB Examples

Test Time Series Data for a Unit Root

This example shows how to test a univariate time series for a unit root. It uses wages data (1900-1970) in the manufacturing sector. The series is in the Nelson-Plosser data set.

Load the Nelson-Plosser data. Extract the nominal wages data.

load Data_NelsonPlosser
wages = DataTable.WN;

Trim the NaN values from the series and the corresponding dates (this step is optional, since the test ignores NaN values).

wDates = dates(isfinite(wages));
wages = wages(isfinite(wages));

Plot the data to look for trends.


The plot suggests exponential growth.

Transform the data using the log function to linearize the series.

logWages = log(wages);
title('Log Wages')

The data appear to have a linear trend.

Test the hypothesis that the series is a unit root process with a trend (difference stationary), against the alternative that there is no unit root (trend stationary). Set 'lags',[7:2:11], as suggested in Kwiatkowski et al., 1992.

[h,pValue] = kpsstest(logWages,'lags',[7:2:11])
h =

  1x3 logical array

   0   0   0

pValue =

    0.1000    0.1000    0.1000

kpsstest fails to reject the hypothesis that the wages series is trend stationary. If the result would have been [1 1 1], the two inferences would provide consistent evidence of a unit root. It remains unclear whether the data has a unit root. This is a typical result of tests on many macroeconomic series.

The warnings that the test statistic " below tabulated critical values" does not indicate a problem. kpsstest has a limited set of calculated critical values. When it calculates a test statistic that is outside this range, the test reports the p-value at the appropriate endpoint. So, in this case, pValue reflects the closest tabulated value. When a test statistic lies inside the span of tabulated values, kpsstest linearly interpolates the p-value.