Collect OLS regression results
4 次查看(过去 30 天)
显示 更早的评论
Hi guys, I am Ambrogio Dalò, an university student.I am using Matlab for my final dissertation and some commands are still not clear.
What I wont to do with the following script is : 1) Create a dependent variable matrix (SRW) 2) clear my dependt variable form colums with less than n oservation 3) regress the regressor matrix (X) on each dependete variable 4) collect all the results for each j in an cell-arrey matrix
I'll explain my script,in order to be as clear as possible.
for j = 1:245; % start the loop j
SRW = SR(j:j+23,:); % create the dependet variable matrix
A = sum(isfinite(SRW)); % sum the finite value for column
I = find(A<16); % find the colum with less than 16 observatios
SRW(:,I(1:end))=[]; % clear the SRW matrix
S = size(SRW); % find the size of SRW matrix
for i = 1:S(1,2); % start the second loop, whose dimension depend from the size of S
Y = SRW(:,i); % create a dependent variable for each column of SRW
X = horzcat(ones(24,1),Factors(j:j+23,5)); % create the regressors matrix
B = NaN(2,i); % preallocate hte Btas matrix
T = NaN(2,i); % preallocate the t-stat matrix
P = NaN(2,i); % preallocate the P-value matrix
R = NaN(1,i); % preallocate the R^2 vector
[B(:,i),T(:,i),P(:,i),R(:,i)] = NaNOLS(X,Y); % make the regression ignoring the NaN values
All = vertcat(B,T,P,R);
ToT(:,j)={All};
end end
Now, my problem is that the only results available are those for the last i-th regression for j=245.The ohters seem to disappear.I think becouse that for each regression matlab overwrite the results.In this way the only results available are the last one. Is there a way to solve this problem?
Thanks in advance for any help
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!