Non-Linear Steady State

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

Non-Linear Steady State

Postby jd1090 » Wed Nov 23, 2016 8:16 am

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.
Attachments
nl_tot.m
(338 Bytes) Downloaded 43 times
nl_tot_sol.m
(82 Bytes) Downloaded 41 times
Justas Dainauskas
Department of Economics and Related Studies
University of York
Heslington
York
YO10 5DD
United Kingdom
jd1090
 
Posts: 62
Joined: Wed Mar 25, 2015 11:12 am

Re: Non-Linear Steady State

Postby jd1090 » Wed Nov 23, 2016 8:30 am

I have now tried to use

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


in the steady_state_model block, but unsuccessfully.
Last edited by jd1090 on Wed Nov 23, 2016 8:37 am, edited 1 time in total.
Justas Dainauskas
Department of Economics and Related Studies
University of York
Heslington
York
YO10 5DD
United Kingdom
jd1090
 
Posts: 62
Joined: Wed Mar 25, 2015 11:12 am

Re: Non-Linear Steady State

Postby jd1090 » Wed Nov 23, 2016 8:37 am

I'm going to try using an external steady state file since it is .m and maybe it will do the trick.
Justas Dainauskas
Department of Economics and Related Studies
University of York
Heslington
York
YO10 5DD
United Kingdom
jd1090
 
Posts: 62
Joined: Wed Mar 25, 2015 11:12 am

Re: Non-Linear Steady State

Postby jpfeifer » Wed Nov 23, 2016 9:26 am

If you want to use a steady_state_model-block, you need a "helper"-function. See the example3.mod in the Dynare examples folder
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Non-Linear Steady State

Postby jd1090 » Wed Nov 23, 2016 9:54 am

Thanks for the reply, but I managed to work it out with an external steady state file quite easily.
Justas Dainauskas
Department of Economics and Related Studies
University of York
Heslington
York
YO10 5DD
United Kingdom
jd1090
 
Posts: 62
Joined: Wed Mar 25, 2015 11:12 am

Re: Non-Linear Steady State

Postby jd1090 » Wed Nov 23, 2016 12:07 pm

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.
Attachments
tot_steadystate.m
(11.66 KiB) Downloaded 55 times
Justas Dainauskas
Department of Economics and Related Studies
University of York
Heslington
York
YO10 5DD
United Kingdom
jd1090
 
Posts: 62
Joined: Wed Mar 25, 2015 11:12 am

Re: Non-Linear Steady State

Postby jpfeifer » Wed Nov 23, 2016 12:44 pm

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.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Non-Linear Steady State

Postby jd1090 » Wed Nov 23, 2016 1:03 pm

Brilliant! Many thanks.
Justas Dainauskas
Department of Economics and Related Studies
University of York
Heslington
York
YO10 5DD
United Kingdom
jd1090
 
Posts: 62
Joined: Wed Mar 25, 2015 11:12 am


Return to Dynare help

Who is online

Users browsing this forum: Google [Bot] and 6 guests