Page 1 of 1

Non-Linear Steady State

PostPosted: Wed Nov 23, 2016 8:16 am
by jd1090
Hi,

I am working on a non-linear open economy model and as is usual in these frameworks the solution to the terms of trade cannot be obtained analytically. I followed the guidance of matlab and can solve for the variables of interest using fsolve. However, I tried to incorpotate it into the mod file, but the steady_state_model block doesn't seem to recognise the command.

I attach my .m files that solve for the two relevant variables x(1) and x(2). The file nl_tot defines the function and the parameters, whereas nl_tot_sol obtains the solution. My question is - how do I incorporate these codes into a mod file? For example, if I just input the following:

Code: Select all
var ...
varexo ...
parameters ...
...
model; ...
steady_state_model;
...
x0=[1 1];
xis=fsolve(@nl_tot,x0);
...
etc.


then dynare crashes as it does not recognise neither "[" nor "@". Should I use another file with @# operator to solve it?

Many thanks.

Re: Non-Linear Steady State

PostPosted: Wed Nov 23, 2016 8:30 am
by jd1090
I have now tried to use

Code: Select all
@#include "nl_tot_sol.m";


in the steady_state_model block, but unsuccessfully.

Re: Non-Linear Steady State

PostPosted: Wed Nov 23, 2016 8:37 am
by jd1090
I'm going to try using an external steady state file since it is .m and maybe it will do the trick.

Re: Non-Linear Steady State

PostPosted: Wed Nov 23, 2016 9:26 am
by jpfeifer
If you want to use a steady_state_model-block, you need a "helper"-function. See the example3.mod in the Dynare examples folder

Re: Non-Linear Steady State

PostPosted: Wed Nov 23, 2016 9:54 am
by jd1090
Thanks for the reply, but I managed to work it out with an external steady state file quite easily.

Re: Non-Linear Steady State

PostPosted: Wed Nov 23, 2016 12:07 pm
by jd1090
One more question. For some reason, the external steady state file (which I copied from the NK_baseline example) is having some problems with loading the parameter values from the model. I haven't changed the loops and they seem correct to me, but in the specification of the above 'function' command, both "ys" and "exo" are underlined in orange by matlab (which indicates that ys may not be used) unlike in the NK_baseline model.

To overcome this, I can simply copy and paste the values of my parameters into the _steadystate.m file, but then everytime I wish to change the parameter values, I need to do this twice. Needless to say, running loops with this approach would be problematic and inefficient. I would like to know what it is that I'm doing wrong.

I attach the results object (which loads the matrix M_ necessary to find the steady states) and the _steadystate.m file, which again works only with parameter values copied into the file (try deleting them and it will crash).

Thanks for the help.

P.S. the .mat file is too large for the forum, so you can download it from here: https://uploadfiles.io/c2e16. But the problem may be obvious from just looking at the _steadystate.m file for an experienced eye.

Re: Non-Linear Steady State

PostPosted: Wed Nov 23, 2016 12:44 pm
by jpfeifer
Matlab will have problems in the steady state file whenever your parameters have the same name as built-in functions (which applies to probably all Greek letters). A workaround is to put a fake initialization before the first loop in the file, i.e.

Code: Select all
function[ys,check]=erpt_steadystate(ys,exo)
global M_
 
beta=0;
%% DO NOT CHANGE THIS PART.
%%
%% Here we load the values of the deep parameters in a loop.
%%
NumberOfParameters = M_.param_nbr;                            % Number of deep parameters.
for ii = 1:NumberOfParameters                                  % Loop...
  paramname = deblank(M_.param_names(ii,:));                   %    Get the name of parameter i.
  eval([ paramname ' = M_.params(' int2str(ii) ');']);         %    Get the value of parameter i.
end                                                           % End of the loop. 
check = 0;


That ys and exo are not used is correct. Tjere are applications where you might need them as inputs, but this is not the case here.

Re: Non-Linear Steady State

PostPosted: Wed Nov 23, 2016 1:03 pm
by jd1090
Brilliant! Many thanks.