External MATLAB function in Dynare

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.

External MATLAB function in Dynare

Postby mary » Wed May 02, 2012 8:52 am

Hello everyone!
I am trying to incorporate a matlab function in Dynare, but it doesn't seem to like it. I have a linearized model, in which some coefficients depend on steady state values. Therefore, I solved for the steady state by hand and I wrote a matlab function (called ssvalues) which, given values for the model parameters, gives the steady state values as outputs. I tried to incorporate this function in my .mod file after the the "parameters" block, when I specify values of parameters. In particular, I coded:
beta = 0.998;
[y_ss, c_ss, otherssvalues_ss] = ssvalues(beta);

When I try to run the .mod file I get the following error message:

STEADY: numerical initial values incompatible with the following equations
Columns 1 through 14

1 2 3 4 5 6 7 8 9 10 11 12 13 14

Columns 15 through 28

15 16 17 18 19 20 21 22 23 25 27 28 29 31

Columns 29 through 31

32 33 34

??? Error using ==> dynare_solve at 94
exiting ...

Error in ==> steady_ at 120
[oo_.steady_state,check] = dynare_solve([M_.fname '_static'],...

Error in ==> steady at 54
steady_;

Error in ==> basesimple at 386
steady;

Error in ==> dynare at 120
evalin('base',fname) ;

Apparently, Dynare does not use the outputs of my function as parameters of the model. :shock: Can anyone tell me why this happens and how can I do tho fix this problem?
Thank you very much!
Best,

Mary
mary
 
Posts: 9
Joined: Thu Feb 23, 2012 2:11 pm

Re: External MATLAB function in Dynare

Postby jpfeifer » Wed May 02, 2012 11:19 am

Please post the mod and the steady state file.
------------
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: External MATLAB function in Dynare

Postby mary » Wed May 02, 2012 12:04 pm

Dear jpfeifer,

Thank you for your reply. In attachment the .mod and the file that calculated the steady state.
Kind regards
Attachments
SOE_ss.m
(4.28 KiB) Downloaded 338 times
SOE.mod
(7.49 KiB) Downloaded 342 times
mary
 
Posts: 9
Joined: Thu Feb 23, 2012 2:11 pm

Re: External MATLAB function in Dynare

Postby jpfeifer » Wed May 02, 2012 12:36 pm

The better way is to write a correct steady state file. It should look like the attached one. The reason for doing so is that your way of defining parameters before the model block is only robust for stoch_simul but will immediately fail as you proceed to estimation.

There are two things you need to do with the attached files: First, in the mod-file delete all parameter initalizations that depend on previous parameters before the model block. They should be moved to the steady state file. Second, make sure that the steady state file only sets these not previously defined parameters. Otherwise you might overwrite already set parameters.

Example: If you set
Code: Select all
beta=0.99;
before the model block, do not use
Code: Select all
beta = 0.9889;      % annual (gross) deposit rate = 4.45%

in the steady state file as you will overwrite the setting in the mod-file. Only use parameter definitions like e.g.
Code: Select all
R = 1/beta;         % domestic risk free rate

in the steady state file that use the parameters already set in the mod-file.
Attachments
SOE.mod
Mod-file
(7.19 KiB) Downloaded 570 times
SOE_steadystate.m
Steady state file setting the parameters
(4.87 KiB) Downloaded 639 times
------------
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: External MATLAB function in Dynare

Postby mary » Wed May 02, 2012 1:08 pm

Dear jpfeifer,

Thank you very much for your reply and your help!!!!!! :D
It works perfectly!!!!

Best regards
mary
 
Posts: 9
Joined: Thu Feb 23, 2012 2:11 pm

Re: External MATLAB function in Dynare

Postby jpfeifer » Wed May 02, 2012 2:47 pm

The steady state file is a Matlab function and not a Dynare-file. Hence it can handle all Matlab functions, including statistical functions.
------------
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: External MATLAB function in Dynare

Postby mary » Wed May 02, 2012 2:50 pm

Just a little extra question. Can the steady state file handle matlab functions such as normcdf and normpdf?
mary
 
Posts: 9
Joined: Thu Feb 23, 2012 2:11 pm

Re: External MATLAB function in Dynare

Postby mary » Wed May 02, 2012 2:51 pm

Thank you!
mary
 
Posts: 9
Joined: Thu Feb 23, 2012 2:11 pm

Re: External MATLAB function in Dynare

Postby ptr » Wed Sep 11, 2013 11:48 am

Dear Dynare Team,

Am having a problem finding steady state with an external matlab function.

I've gone through various discussion on the subject at the forum and am stuck in resolving the steady state and need some assistance.

The error messages am receiving on running the .mod and _steadystate.m files attached are:

??? Error using ==> beta at 21
Not enough input arguments.

Error in ==> CC_steadystate at 62
R_n=log(1/beta);

Error in ==> evaluate_steady_state_file at 49
[ys,check] = h_steadystate(ys_init, exo_ss);

Error in ==> evaluate_steady_state at 58
[ys,params,info] = evaluate_steady_state_file(ys_init,exo_ss,M, ...

Error in ==> steady_ at 54
[steady_state,params,info] =
evaluate_steady_state(oo_.steady_state,M_,options_,oo_,~options_.steadystate.nocheck);
Error in ==> steady at 81
[steady_state,M_.params,info] = steady_(M_,options_,oo_);

Error in ==> CC at 292
steady;

Error in ==> dynare at 120
evalin('base',fname) ;

Your assistance is appreciated a lot.
CC_steadystate.m
(1.8 KiB) Downloaded 140 times
Attachments
CC.mod
(7.01 KiB) Downloaded 136 times
ptr
 
Posts: 30
Joined: Fri Apr 19, 2013 9:58 am

Re: External MATLAB function in Dynare

Postby jpfeifer » Sat Sep 14, 2013 8:05 am

You comitted one of the deadly Dynare sins. Thou shalt not use variable or parameter names that are built-in Matlab functions. Beta is the Matlab command for the beta-distribution. As soon as you try to use it in an external function, you get the error message.
------------
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: External MATLAB function in Dynare

Postby ptr » Sat Sep 14, 2013 9:10 am

Thanks Jpfeifer for the guidance on the Dynare sin.

I've made correction to the steadystate.m file and am getting the errors below. I've tried inputting different guess values without success. Which new sin am I committing that make my file not to run?

??? Error using ==> print_info at 55
The steadystate file did not compute the steady state

Error in ==> resid at 116
print_info(info,options_.noprint)

Error in ==> steady at 90
resid;

Error in ==> CC1 at 292
steady;

Error in ==> dynare at 120
evalin('base',fname) ;

Revised .m file is herewith attached. Thanks in advance.
Attachments
CC1.mod
(7.01 KiB) Downloaded 136 times
CC1_steadystate.m
(1.81 KiB) Downloaded 131 times
ptr
 
Posts: 30
Joined: Fri Apr 19, 2013 9:58 am

Re: External MATLAB function in Dynare

Postby jpfeifer » Sat Sep 14, 2013 9:50 am

No sin. Just that your steady state file does not compute a valid steady state. The residuals implied by your file are:

Residuals of the static equations:

Equation number 1 : -31.7922
Equation number 2 : -1188.0405
Equation number 3 : 0.054918
Equation number 4 : -3.0626
Equation number 5 : 38518.3595
Equation number 6 : -37.7933
Equation number 7 : -87.9047
Equation number 8 : -0.038101
Equation number 9 : -1.7184
Equation number 10 : 102813.1407
Equation number 11 : 0.18443
Equation number 12 : 0.048499
Equation number 13 : -118052.6787
Equation number 14 : 8093.504
Equation number 15 : -43494.0202
Equation number 16 : 11082.6463
Equation number 17 : 0.42623
Equation number 18 : 0
Equation number 19 : 0
Equation number 20 : -0.53106
Equation number 21 : -11082.6463
Equation number 22 : 0
Equation number 23 : 0
Equation number 24 : 886.1558
Equation number 25 : 3.3151
Equation number 26 : 1.9579
Equation number 27 : -2.7183
Equation number 28 : -2.7183
Equation number 29 : 1.7183
Equation number 30 : 0.81548
Equation number 31 : 1.7183
Equation number 32 : -1.7183
Equation number 33 : -0.68647
------------
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


Return to Dynare help

Who is online

Users browsing this forum: No registered users and 10 guests