%% Test Trend Stationarity by Specifying Lags
% Test whether the wage series in the manufacturing sector (1900-1970) has a unit root.
% Load the Nelson-Plosser Macroeconomic data set.

load Data_NelsonPlosser
wages = DataTable.WN;
T = sum(isfinite(wages)); % Sample size without NaNs
sqrtT = sqrt(T) % See Kwiatkowski et al., 1992

%
% Plot the wages series.

plot(dates,wages)
title('Wages')
axis tight

% The plot suggests that the wages series grows exponentially.
%
% Linearize the wages series.

logWages = log(wages);
plot(dates,logWages)
title('Log Wages')
axis tight

% The plot suggests that the log wages series has a linear trend.
%
% Test the hypothesis that the log wages series is a unit root process with a trend (i.e., difference stationary), against the alternative that there is no unit root (i.e., trend stationary). Conduct the test by setting a range of lags around \sqrt{T}, as suggested in Kwiatkowski et al., 1992.

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

% All tests fail to reject the null hypothesis that the log wages series is trend stationary.
% The p-values are larger than 0.1. The software compares the test statistic to critical values and computes p-values that it interpolates from tables in Kwiatkowski et al., 1992.
% Copyright 2015 The MathWorks, Inc.