Integration in Dynare 4

Hello everyone! I am currently writing my master thesis and I would like to build a search and matching model in Matlab with the help of Dynare. I found a paper that built a similar model, but with version 3 of Dynare. As there is an integral used in the model, this does not work with version 4. Could you please help me in solving the problem?

Figure7_a-2.mod (1.4 KB)
afa4.m (144 Bytes)

It seems you need to define an external_function. Search the forum.

I already did, but I could not figure out how to define the external function in my case. So I have to define an external function for the integral function right? But after that can I still refer to my function which is saved as afa4.m?

An example is at

Thanks for your help. But I don’t understand what is done in the example. What kind of function does he define with the external function? Do I need to specify the function in a separate m file?

Yes, the separate m-file is at

Okay, thanks. But what do I do If I need to specify both a function (afa4) and the integral function (Quad), which Dynare does not know. Do I need two separate m files then?

Could you please elaborate on what you exactly need to do. What are the things you need to compute in your model and on what do the functions you need to compute depend (which parameters and variables)

I want to create impulse response functions. In the model section I need to compute the integral of a function, which is saved in a separate m.file (afa4.m, I uploaded it earlier). In the original mod file, the authors calculated the integral as follow: quad(@afa4, vk,vf) (line 47 of Figure7_b.mod). But because version 4 of Dynare does not accept the quad function, I need to specify an external function. Do I have to save the function (afa4) and the quad function (of afa4) in the same m-file? I will upload the Figure7_b.mod file, so you can have a look at it (line 47).Figure7_b.mod (2.2 KB)

Do you have any suggestions for how to solve this problem? Thank you in advance.

Attached is a working version:
stw5_EU_calib_noQI_fc0225_Co0.csv (459 Bytes) Figure7_b_4.mod (2.6 KB) quad_afa4.m (174 Bytes) quad_afa5.m (177 Bytes)
It eliminates the global variable as well.

Hello everyone,

I run into this post a few months ago and now I am wondering is there a way to rewrite the equations that use the external functions in a way that we do not need the external functions anymore? I need this because I want to change the distribution used in this model from a logistic distribution to a uniform distribution.
I’ve tried rewriting the equations without the external functions, but unfortunately I don’t end up with the same steady state values meaning I did something wrong.

Thanks in advance!

Why not stick with external functions and write a separate function file this time for uniform distribution instead of logistics distribution? Did you consider this option?

I am not sure I understand the problem. For the uniform distribution you should have easy closed form formulas available that don’t require external functions.

Yes for some of the equations that works easy.

The problem arises for me with the equations such as QI which is the expected value of operating costs for incumbent workers, conditional on not being fired. The same goes for QK and QY. How do I implement the conditional term in these equations using the uniform distribution? Any tips on that?


Can you post the file or a screen grab of relevant equations?

I use the same files provided above: stw5_EU_calib_noQI_fc0225_Co0.csv (459 Bytes) Figure7_b_4.mod (2.6 KB) quad_afa4.m (174 Bytes) quad_afa5.m (177 Bytes).




You should explain the economic problem you are trying to solve in sufficient detail for others to be able to understand them. Clinging to an old, undocumented implementation of a different model is not helpful.