External MATLAB function in Dynare

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. :open_mouth: Can anyone tell me why this happens and how can I do tho fix this problem?
Thank you very much!
Best,

Mary

Please post the mod and the steady state file.

Dear jpfeifer,

Thank you for your reply. In attachment the .mod and the file that calculated the steady state.
Kind regards
SOE_ss.m (4.28 KB)
SOE.mod (7.49 KB)

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 beta=0.99; before the model block, do not use

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.

R = 1/beta; % domestic risk free rate
in the steady state file that use the parameters already set in the mod-file.
SOE.mod (7.19 KB)
SOE_steadystate.m (4.87 KB)

Dear jpfeifer,

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

Best regards

The steady state file is a Matlab function and not a Dynare-file. Hence it can handle all Matlab functions, including statistical functions.

Just a little extra question. Can the steady state file handle matlab functions such as normcdf and normpdf?

Thank you!

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 KB)
CC.mod (7.01 KB)

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.

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.
CC1.mod (7.01 KB)
CC1_steadystate.m (1.81 KB)

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

[quote]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[/quote]