I am running some regression in matlab.
I want to store the varibles nicely through structures.
Here is some code:
clc;
clear;
fruit_names={'Apple','Pear','Melon'};
Predictors.Apple = rand(500,11);
Predictors.Pear = rand(500,11);
Predictors.Melon = rand(500,11);
Returns.Apple = rand(500,1);
Returns.Pear = rand(500,1);
Returns.Melon = rand(500,1);
%%
kk=1;
for d = 1:length(fruit_names)
for i = [1,2,3,4,5,6,12,24,48,60]
for jj = 1:11
K = i;
xinit=[Predictors.(fruit_names{d})(:,jj)];
yinit=Returns.(fruit_names{d});
[b,bint,r,rint,stats] = regress(yinit,xinit);
Stats.(fruit_names{d})(kk+1)=stats(1);
kk=kk+1;%to help with reporting
end
end
end
It honestly my best attempt at a simple example. It does require the Econometrics toolbox if I remember correctly.
The problem I am having is the structure Stats stores the results I need but after the first variables include some useless zeros.
I have posted and deleted an earlier question which suggests removing the (kk,:) variables, but if I do this it only contains the final results not the evolution of results through the for loop.
kkfor eachfruit_names, otherwise after the first fruit is proccessed,kkalready reached value11xnumel(i)=110. When the next fruit is processed,kkstarts at 111 ...