Dear MATLAB expers,
I'm trying to run many linear regressions each one consisting of one dependent variable and an independent variable, but I keep on stumbling upon the following error:
Unable to perform assignment because the left and right sides have a different number of elements.
Error in code (line 739)
tStat(i) = bint; % t-Statistic
It is an error concerning the size of 'tStat', 'Residuals', 'Outliers' and 'RegressStats' and I don't know how to fix it.
[NumRows, NumSeries] = size(stockReturns);
NumAssets = NumSeries - 2;
StartDate = datestr(stockReturnsDates(1));
EndDate = datestr(stockReturnsDates(end));
Alpha = NaN(1, length(NumAssets));
Beta = NaN(1, length(NumAssets));
tStat = zeros(1818, 2, 2);
Residuals = NaN(length(NumAssets), 2);
Outliers = NaN(length(NumAssets), 2);
RegressStats = NaN(length(NumAssets), 2);
DependentVariable = zeros(NumRows,1);
IndependentVariable = zeros(NumRows,2);
DependentVariable(:) = stockReturns(:,i) - stockReturns(:,1827);
IndependentVariable(:,1) = 1.0;
IndependentVariable(:,2) = stockReturns(:,1826) - stockReturns(:,1827);
[b, bint, r, rint,stats] = regress(DependentVariable, IndependentVariable, 5);
I would really appreciate your help since I've been stuck with this error for a while already.