%% Convert VEC Model to VAR Model Using Cell Arrays
% Consider converting the following VEC(2) model to a VAR(3) model.
% \begin{array}{rcl}\Delta {y_t} &=& \left[ {\begin{array}{*{20}{c}}
% {0.5}\\
% {1}\\
% { - 2}
% \end{array}} \right] + \left[ {\begin{array}{*{20}{c}}
% { - 0.14}&{0.12}&{ - 0.05}\\
% { - 0.14}&{ - 0.07}&{ - 0.10}\\
% { - 0.07}&{ - 0.16}&{ - 0.07}
% \end{array}} \right]\Delta {y_{t - 1}} + \left[ {\begin{array}{*{20}{c}}
% { - 0.14}&{0.12}&{ - 0.05}\\
% { - 0.14}&{ - 0.07}&{ - 0.10}\\
% { - 0.07}&{ - 0.16}&{ - 0.07}
% \end{array}} \right]\Delta {y_{t - 2}}\\ &+& \left[ {\begin{array}{*{20}{c}}
% { - 0.32}&{0.74}&{ - 0.38}\\
% {1.97}&{ - 0.61}&{0.44}\\
% { - 2.19}&{ - 1.15}&{2.65}
% \end{array}} \right]{y_{t - 1}} + {\varepsilon _t}\end{array}.
% Specify the coefficient matrices (B_1 and B_2) of \Delta y_{t-1} and \Delta y_{t-2}, and the error-correction coefficient C.

B1 = [-0.14   0.12 -0.05;
      -0.14 -0.07 -0.10;
      -0.07  -0.16 -0.07];
B2 = [-0.14   0.12 -0.05;
      -0.14 -0.07 -0.10;
      -0.07  -0.16 -0.07]; 
C  = [-0.32  0.74 -0.38;
       1.97 -0.61  0.44;
     - 2.19 -1.15  2.65];

%
% Pack the matrices into separate cells of a 2-dimensional cell vector. Put B1 into the first cell and B2 into the second cell.

VEC = {B1 B2};

%
% Compute the coefficient matrices of the equivalent VAR(3) model.

VAR = vec2var(VEC,C);
size(VAR)

% The specification of a cell array of matrices for the input argument indicates that the VEC(2) model is in reduced form, and VEC{1} is the coefficient of \Delta y_{t-1}. Subsequent elements correspond to subsequent lags.
% VAR is a 1-by-3 cell vector of 3-by-3 coefficient matrices for the VAR(3) equivalent of the VEC(2) model. Because the VEC(2) model is in reduced form, the equivalent VAR(3) model is as well. That is, VAR{1} is the coefficient of y_{t-1}, and subsequent elements correspond to subsequent lags. The orientation of VAR corresponds to the orientation of VEC.
%
% Display the VAR(3) model coefficients.

A1 = VAR{1}
A2 = VAR{2}
A3 = VAR{3}

% Since the constant offsets between the models are equivalent, the resulting VAR(3) model is
% {y_t} = \left[ {\begin{array}{*{20}{c}}
% {0.5}\\
% {1}\\
% { - 2}
% \end{array}} \right] + \left[ {\begin{array}{*{20}{c}}
% {0.54}&{0.86}&{ - 0.43}\\
% {1.83}&{0.32}&{0.34}\\
% { - 2.26}&{ - 1.31}&{3.58}
% \end{array}} \right]{y_{t - 1}} + \left[ {\begin{array}{*{20}{c}}
% {0.14}&{ - 0.12}&{0.05}\\
% {0.14}&{0.07}&{0.10}\\
% {0.07}&{0.16}&{0.07}
% \end{array}} \right]{y_{t - 3}} + {\varepsilon _t}.
% Copyright 2015 The MathWorks, Inc.