%% Compare Several VEC Model Fits
% Consider the model and data in Estimate VEC Model and these four alternative VEC models: VEC(0), VEC(1), VEC(3), and VEC(7). Using historical data, estimate each of the four models, and then compare the model fits using the resulting Bayesian Information Criterion (BIC).
% Load the Data_USEconVECModel data set and preprocess the data.

load Data_USEconVECModel
FRED.GDP = 100*log(FRED.GDP);      
FRED.GDPDEF = 100*log(FRED.GDPDEF);
FRED.COE = 100*log(FRED.COE);       
FRED.HOANBS = 100*log(FRED.HOANBS); 
FRED.PCEC = 100*log(FRED.PCEC);     
FRED.GPDI = 100*log(FRED.GPDI);

%
% Within a loop:
% Create a VEC model using the shorthand syntax.
% Estimate the VEC Model. Reserve the maximum value of p as presample observations.
% Store the estimation results.

numlags = [0 1 3 7];
p = numlags + 1;
Y0 = FRED{1:max(p),:};
Y = FRED{((max(p) + 1):end),:};

for j = 1:numel(p)
    Mdl = vecm(7,4,numlags(j));
    EstMdl = estimate(Mdl,Y,'Y0',Y);
    results(j) = summarize(EstMdl);
end

% results is a 4-by-1 structure array containing the estimation results of each model.
% Extract the BIC from each set of results.
%

BIC = [results.BIC]

% The model corresponding to the lowest BIC has the best fit among the models considered. Therefore, the VEC(0) model is the best fitting model.
% Copyright 2012 The MathWorks, Inc.