%% Assess Whether a Series Is Trend Stationary and AR(p)
% Test the growth of the U.S. unemployment rate using the data in Schwert, 1987.
% Load Schwert's macroeconomic data set. Convert the table of monthly series to a timetable.

load Data_SchwertMacro
dates = datetime(datesMth,"ConvertFrom","datenum");
TT = table2timetable(DataTableMth,"RowTimes",dates);

%
% Focus on the unemployment rate growth over the dates considered in Leybourne and McCabe, 1999.

trLM = timerange("1948-01-01","1985-12-01","closed");
unLM = TT.UN(trLM);
dUNLM = diff(unLM); % Unemployment growth rate

%
% Assess the null hypothesis that the unemployment rate growth is a trend stationary, AR(1) process using the estimated variance from OLS regression.

[h1,~,stat1,cValue] = lmctest(dUNLM,"Lags",1,"Test","var1")

% h1 = 0 indicates that there is not enough evidence to reject that the unemployment rate growth is a trend stationary, AR(1) process.
%
% Assess the null hypothesis that the unemployment rate growth is a trend stationary, AR(1) process using the estimated variance from the maximum likelihood of the reduced-form regression model.

[h2,~,stat2,cValue] = lmctest(dUNLM,"Lags",1,"Test","var2")

% h2 = 1 indicates that there is enough evidence to suggest that the unemployment rate growth is nonstationary.
% Leybourne and McCabe, 1999 report that the original LMC statistic fails to reject stationarity, while the modified LMC statistic does reject it.
% Copyright 2021 The MathWorks, Inc.