Is it wrong to put 'end' after certain sections, or does the problem lie in other codes?

7 views (last 30 days)
I know it is required to put 'end' after certain lines, so if an error pops out, something must be wrong with my other codes. But I can't figure our what is wrong. Can anyone help? Thank you very much!
var h hm hf x yf yfi yff ym y theta;
varexo eps_x,
parameters rho_x alpha delta STDERR_x;
delta=2;
alpha=0.4;
STDERR_x=0.5;
rho_x=0.95;
model;
h=hm+hf;
hf=x*h;
hm=(1-x)*h;
yf=(hf)^(1/delta);
yfi=theta*yf;
yff=(1-theta)*yf;
theta=hm;
ym=(yfi)^alpha*(hm)^(2-alpha);
y=(1-theta)*yf+ym;
x=rho_x*x(-1)+eps_x;
end;
initval;
h=0;
hf=0;
hm=0;
yf=0;
yfi=0;
yff=0;
theta=0;
ym=0;
y=0;
x=0;
end;
steady;
check;
shocks;
var eps_x; stderr STDERR_x;
end;
stoch_simul(dr_algo=0,order=1,irf=60) y ym yf yff yfi hm hf;

Accepted Answer

the cyclist
the cyclist on 17 Aug 2021
The first few lines of what you have posted here are not valid MATLAB code. Are you trying to convert from some other programming language?
Similarly, statements like
model;
do nothing in MATLAB. It is very unclear what you are trying to achieve.
As stated in the documentation for end, that keyword is only used to terminate code blocks such as if statements, for loops, functions, etc. It is incorrect to use it in any other context.
So ... this code needs a lot of help.
  2 Comments
Walter Roberson
Walter Roberson on 17 Aug 2021
Remember command/function duality.
var h hm hf x yf yfi yff ym y theta;
calls function named var passing in 'h', 'hm', 'hf', 'x', 'yf', 'yfi', 'yff', 'ym', 'y', 'theta' . Completely valid MATLAB by itself, even if the code was not being pre-processed by Dynare.
The several end statements are a potential problem for pure MATLAB that is not being pre-processed.
stoch_simul(dr_algo=0,order=1,irf=60) y ym yf yff yfi hm hf;
until a couple of releases ago, the = in the middle of the line would have been a problem in pure MATLAB; now it would be equivalent to
stoch_simul('dr_algo', 0, 'order', 1, 'irf', 60) y ym yf yff yfi hm hf;
so the first part of that would be acceptable MATLAB. However, the y onwards would be a syntax problem in pure MATLAB

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 17 Aug 2021
You can't just go dropping "end" statements wherever you want. You put them after
  1. an "if" statement or
  2. a "while" statement
  3. a "switch" statement
  4. a "function" statement (except in a GUIDE .fig file).
to close or finish off that block of code. You can't just put them anywhere at random hoping it will help, or at least be harmless. It doesn't work that way. In the code you posted, you put the end statements in places where it just doesn't make sense since it's not closing off one of those cases I listed above.
  3 Comments
Image Analyst
Image Analyst on 17 Aug 2021
Never heard of it, and she didn't mention it. She just shows a very badly-named file called "try.m"
But you are probably right. And there you go again, showing off with your Mind Reading Toolbox. 😄 I need a copy of that.

Sign in to comment.

Categories

Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!