Clear Filters
Clear Filters

Several regression with loop and storing the output data

4 views (last 30 days)
I have a matrix of dependent variables DATI 570x2604 (each column represents a time series), and a second matrix of regressors REG 570x10416. I want to regress the first column of DATI on the first 4 columns (1 to 4) of REG, then the second column of DATI on the second 4 columns (5 to 8) of REG. Is there a chance to run the 2604 regressions with a loop and to store the estimated coefficients t stat p value and r2 in a matrix?
I’m very new to matlab and any help would be an asset.

Answers (1)

Ben Drebing
Ben Drebing on 20 Dec 2017
Try this code out:
for i = 1:2604
% Get the ith column of DATI
Y = DATI(:,i);
% Get the 4i+1 th to the 4i+4 th columns of REG
X = [ones(570,1), REG(:,(4*i+1):(4*i+4))];
[b, bint,r,rint,stats] = regress(Y,X);
This will do the regressions that you were talking about. The outputs of the "regress" function, specifically the "stats" variable, will have the statistics that you wanted to save. You can read about which outputs are which here.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!