First off, the interior (j) part of your loop doesn't make any sense, for several reasons:
(1) Everything inside that loop is based on the first line
VAR_{j} = fitlm(lag1_beta, beta(:, i), 'Intercept', false);
but there is no j on the right-hand side, so nothing would change as you interate through different values of j. I don't even have a guess as to what you want to change as j iterates.
(2) Note that ['level', 'slope', 'curv']='levelslopecurv'. Thus, when you write
for j =['level', 'slope', 'curv']
MATLAB interprets this as "cycle through the letters of 'levelslopecurv' one at a time, so that first j='l', then j='e', etc.". Hopefully you can see that this makes no sense.
(3) When j is a character (as (2) just established), and you use j as an index (e.g., as you did with VAR_{j}), MATLAB first converts the character to its ASCII code (e.g., 'l' becomes 108, since char(108)='l', etc.), and then uses that ASCII code as the index. There is no chance that's actually what you want here.
(4) The line
a{i} = VAR_{j}.Coefficients.Estimate';
overwrites a{i} (the i-th element of the cell array a) for each value of j. Again, this makes no sense.
Leaving aside the j business since I don't understand what you're trying to do with that, you don't need to do this for one equation at a time. If
is your regression equation, with the identifying assumption
, then substituing
into the latter, you can solve for
.Assuming you have T periods of observed data, letting
be the
matrix whose t-th row is
, and
the
matrix whose t-th row is
, and estimator of A is then Thus, all you need to do in your case is
Y0 = beta(1:end-1,:);
Y1 = beta(2:end,:);
A = (Y1'*Y0)/(Y0'*Y0);