%% Specify Presample Values
% Consider the model and data in Estimate VEC Model, and suppose that the estimation sample starts at Q1 of 1980.
% 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);

%
% Identify the index corresponding to the start of the estimation sample.

estIdx = FRED.Time(2:end) > '1979-12-31';

%
% Create a default VEC(1) model using the shorthand syntax. Assume that the appropriate cointegration rank is 4. Specify the variable names.

Mdl = vecm(7,4,1);
Mdl.SeriesNames = FRED.Properties.VariableNames;

%
% Estimate the model using the estimation sample. Specify all observations before the estimation sample as presample data. Also, specify estimation of the H Johansen form of the VEC model, which includes all deterministic parameters.

Y0 = FRED{~estIdx,:};
EstMdl = estimate(Mdl,FRED{estIdx,:},'Y0',Y0,'Model',"H")

% Because the VEC model order p is 2, estimate uses only the last two observations (rows) in Y0 as a presample.
% Copyright 2012 The MathWorks, Inc.