Hello,
nobs = length(hpc);
x = log(gdp);
n = log(hpc);
c = log(cy);
x = x-x(1);
n = n-n(1);
dx = x(2:nobs)-x(1:nobs-1);
dn = n(2:nobs)-alpha*n(1:nobs-1);
x = [dn,dx,c]; %the ordering of the variables
I declared my variables like above. gdp and hpc are nonstationary. They enter into the VAR as first difference but CY(consumption to output ratio) is stationary in level so I do not need to take the first difference of that. The problem is that when I run it, I got the error in below.
Which dataset? ("help ir" shows 12 options)
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
Error in ir (line 267)
x = [dn,dx,c]; %the ordering of the variables
However, If I take the first difference of the CY as well, it runs perfectly. I mean x = [dn,dx,dc]; %the ordering of the variables. So is anyone can help me to solve my issue?
Lastly, the size of my data:
sx =
44 1
sn =
44 1
sc =
44 1
Best, Aysegul

 Accepted Answer

Adam
Adam on 2 Mar 2017

0 votes

As the error says, the dimensions of the arrays you are trying to concatenate are not equal. At a guess, since you are doing differences I imagine one or more of your vectors is 1 element shorter than at least one other as always happens with diff type operations on an array where your answers are between all the original data points.

6 Comments

Hi Adam, Thanks for writing. Yes, I know that but the issue is that I do not know how to fix it. Do you have any idea about how I can correct that?
AYSEGUL DILSIZ
AYSEGUL DILSIZ on 2 Mar 2017
Edited: AYSEGUL DILSIZ on 2 Mar 2017
I think I should express c as c = log(cy(2:nobs)); ???
How to fix it is beyond a simple Matlab problem, it is an interpretation problem if you are trying to concatenate something on, for example, a grid of 0:1:10 and something on a grid of 0.5:1:9.5.
You can put them in a cell array if you want, where things don't have to be the same length, but I don't know why you need them concatenated in a single variable, what you intend to do with them afterwards and how you would expect the mismatch in grids to be handles by whatever further processing you do.
Hey, I think I am bit lost what you said. I am trying to obtain impulse responses for these 3 variables. I have a excel file for one country (say USA). This file has 3 columns gdp, hours and consumption to output ratio. I attached my m file. Actually, it runs when I express c as c = log(cy(2:nobs));
I would greatly appreciate if you could have a look at it.
If changing that makes it work the it is obviously c that has one more element than dn and dx and that is because they are difference results so this is expected.
Again, it is entirely up to interpretation as to how to solve it though. Throwing away the first element of your c vector will solve the horzcat problem, but means your c vector is half a sample off from the results in dn and dx. Whether that is acceptable for what you are doing or not I really don't know, I am just trying to help with the pure Matlab problem, I don't have domain expertise in what you are doing.
Hi Adam, Thanks again. I hope that there will be other explanation about it. For now, I put c as c = log(cy(2:nobs)); and it makes sense to me.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!