Error using regstats (RESPONSES and DATA must have the same number of rows)

2 views (last 30 days)
Hello!
I must deliver the code for an Econometrics exam and everything is running smoothly except for the following error:
Error using regstats
RESPONSES and DATA must have the same number of rows.
Error in FinancialEconometrics_Homework (line 515)
out=regstats(PInde(:,i),F);
that refers to this part of the code:
out=regstats(PInde(:,i),F);
APToutBtM(i,1:6)=out.beta';
APToutBtM(i,7:12)=out.tstat.t';
APToutBtM(i,13)=out.adjrsquare;
APTresBtM(:,i)=out.r;
I don't know how to solve the problem.
PInde is a 97x25 double matrix and F is a 403x5 double matrix.
Could you please help me?
Thank you

Accepted Answer

Walter Roberson
Walter Roberson on 6 Mar 2024
regstats(y,X,model) performs a multilinear regression of the responses in y on the predictors in X. X is an n-by-p matrix of p predictors at each of n observations. y is an n-by-1 vector of observed responses.
So the number of rows of X and y must be the same.
You are using PIndel(:,i) as the y, which will be 97 x 1
You are using F as the X, which will be 403 x 5.
The number of rows of 97 x 1 does not match the number of rows of 403 x 5, so this will fail.
  5 Comments
Walter Roberson
Walter Roberson on 7 Mar 2024
intercept = ones(size(Me));
intercept = intercept(:,1);
What is the point of that? Why not just
intercept = ones(size(Me,1),1);
FEDERICA
FEDERICA on 7 Mar 2024
You're right, thank you for your suggestion! I'm really sorry, I'm still learning to write codes in MatLab and often I just make the same things my professor does during the lectures.

Sign in to comment.

More Answers (1)

FEDERICA
FEDERICA on 8 Mar 2024
Problem solved! Thank you for your help :)

Tags

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!