# How to write a function which include integral sign inside the function

**URL:** <https://forum.dynare.org/t/how-to-write-a-function-which-include-integral-sign-inside-the-function/16381>\
**Category:** General DSGE Modeling\
**Created:** [5 August 2020 16:54 UTC](https://forum.dynare.org/t/how-to-write-a-function-which-include-integral-sign-inside-the-function/16381 "2020-08-05T16:54:13Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Goher](https://forum.dynare.org/letter_avatar_proxy/v4/letter/g/b9e5f3/32.png) [@Goher](https://forum.dynare.org/u/Goher)\
**Post date:** [5 August 2020 16:54 UTC](https://forum.dynare.org/t/how-to-write-a-function-which-include-integral-sign-inside-the-function/16381/1 "2020-08-05T16:54:13Z")

</div>

Hello, I am replicating a paper on search and matching with endogenous job separation. All value functions are included in equilibrium equations and there is integral with upper and lower limit in all value functions. Can anybody help me how to write these values functions with integral in dynare codes

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [6 August 2020 08:39 UTC](https://forum.dynare.org/t/how-to-write-a-function-which-include-integral-sign-inside-the-function/16381/2 "2020-08-06T08:39:47Z")

</div>

The question is on what these integrals depend. If they depend on endogenous variables so that derivatives are required, then you may have to go for an external function. See e.g. [Integration in Dynare 4](https://forum.dynare.org/t/integration-in-dynare-4/14262)

---

<div class="post-metadata">

**Author:** ![Goher](https://forum.dynare.org/letter_avatar_proxy/v4/letter/g/b9e5f3/32.png) [@Goher](https://forum.dynare.org/u/Goher)\
**Post date:** [11 August 2020 17:52 UTC](https://forum.dynare.org/t/how-to-write-a-function-which-include-integral-sign-inside-the-function/16381/3 "2020-08-11T17:52:08Z")

</div>

Thank you for your reply. I have 4 value functions which i have to write in my codes. Do i need external function of each of them or i can use one external function for all.

Thanking in anticipation

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [13 August 2020 12:53 UTC](https://forum.dynare.org/t/how-to-write-a-function-which-include-integral-sign-inside-the-function/16381/4 "2020-08-13T12:53:24Z")

</div>

Without details, it is impossible to know. Often, you can define the whole object with the integral recursively as a separate variable so that integrals do not appear anywhere.

---

<div class="post-metadata">

**Author:** ![Goher](https://forum.dynare.org/letter_avatar_proxy/v4/letter/g/b9e5f3/32.png) [@Goher](https://forum.dynare.org/u/Goher)\
**Post date:** [25 August 2020 12:34 UTC](https://forum.dynare.org/t/how-to-write-a-function-which-include-integral-sign-inside-the-function/16381/7 "2020-08-25T12:34:32Z")

</div>

Hello,  
Thank you for your reply. I am replicating paper of (Miyamoto et.al 2019) and following is the value function of filled job.  
Jt=At_f_(kt_ht)-(wt_xt_ht)-rt_kt-xt+SDF\*((1-rho^x\*(integralunderline(x)^(xbar(t+1))_J(t+1)_(x(t+1)\*Gamma(x(t+1)+(1-(1-rho^(x))_Gamma_xbar(t+1))\*V(t+1))

Can you please explain how i can write it recursilvey?  
best

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [25 August 2020 13:48 UTC](https://forum.dynare.org/t/how-to-write-a-function-which-include-integral-sign-inside-the-function/16381/8 "2020-08-25T13:48:26Z")

</div>

Which paper exactly is it?

---

<div class="post-metadata">

**Author:** ![Goher](https://forum.dynare.org/letter_avatar_proxy/v4/letter/g/b9e5f3/32.png) [@Goher](https://forum.dynare.org/u/Goher)\
**Post date:** [25 August 2020 14:30 UTC](https://forum.dynare.org/t/how-to-write-a-function-which-include-integral-sign-inside-the-function/16381/9 "2020-08-25T14:30:35Z")

</div>

This is the paper.  
[Fiscal Stimulus and Unemployment Dynamics.pdf](https://forum.dynare.org/uploads/short-url/zhar3DZLIIPn7EYALPIoyb1uJ7G.pdf) (1012.0 KB)

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [26 August 2020 08:40 UTC](https://forum.dynare.org/t/how-to-write-a-function-which-include-integral-sign-inside-the-function/16381/10 "2020-08-26T08:40:10Z")

</div>

Have you asked the authors how they did this? It may be the easiest to linearize the equations by hand.

---

<div class="post-metadata">

**Author:** ![Goher](https://forum.dynare.org/letter_avatar_proxy/v4/letter/g/b9e5f3/32.png) [@Goher](https://forum.dynare.org/u/Goher)\
**Post date:** [23 October 2020 12:20 UTC](https://forum.dynare.org/t/how-to-write-a-function-which-include-integral-sign-inside-the-function/16381/11 "2020-10-23T12:20:09Z")

</div>

Yes i have asked but they did not reply. Dynare can find the steady state and linearize the model if the i follow the restrictions on the parameters or is it necessary to linearize the model?

best

---

<div class="post-metadata">

**Author:** ![Goher](https://forum.dynare.org/letter_avatar_proxy/v4/letter/g/b9e5f3/32.png) [@Goher](https://forum.dynare.org/u/Goher)\
**Post date:** [19 November 2020 22:08 UTC](https://forum.dynare.org/t/how-to-write-a-function-which-include-integral-sign-inside-the-function/16381/12 "2020-11-19T22:08:13Z")

</div>

Hello,

These integrals are just showing the cumulative distribution with the range of (0,1). Do i still need to write integral as an external function?

best

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [20 November 2020 07:56 UTC](https://forum.dynare.org/t/how-to-write-a-function-which-include-integral-sign-inside-the-function/16381/13 "2020-11-20T07:56:50Z")

</div>

Which integrals exactly are you referring to. Also, if you don’t know the distribution, then computing a CDF is hard…

---

<div class="post-metadata">

**Author:** ![Goher](https://forum.dynare.org/letter_avatar_proxy/v4/letter/g/b9e5f3/32.png) [@Goher](https://forum.dynare.org/u/Goher)\
**Post date:** [4 December 2020 19:57 UTC](https://forum.dynare.org/t/how-to-write-a-function-which-include-integral-sign-inside-the-function/16381/14 "2020-12-04T19:57:15Z")

</div>

Thank you for your reply. As you suggested i lineairzed the model and try to estimate it but i am facing following error in my estimation.  
In evaluate\_steady\_state (line 263)  
In steady\_ (line 55)  
In steady (line 81)  
In linear\_model (line 361)  
In dynare (line 233)  
In Untitled2 (line 3)  
Warning: Matrix is singular to working precision.  
STEADY: No steady state for your model could be found  
STEADY: Check whether your model is truly linear. Put “resid(1);” before “steady;” to see the problematic equations.

Residuals of the static equations:

Equation number 1 : NaN  
Equation number 2 : NaN  
Equation number 3 : NaN  
Equation number 4 : NaN  
Equation number 5 : NaN  
Equation number 6 : NaN  
Equation number 7 : NaN  
Equation number 8 : NaN  
Equation number 9 : NaN  
Equation number 10 : NaN  
Equation number 11 : NaN  
Equation number 12 : NaN  
Equation number 13 : NaN  
Equation number 14 : NaN  
Equation number 15 : NaN  
Equation number 16 : NaN  
Equation number 17 : NaN  
Equation number 18 : -85.0098  
Equation number 19 : -75.01

Error using print\_info (line 90)  
The steady state contains NaN or Inf

Error in steady (line 104)  
print\_info(info,options\_.noprint, options\_);

Error in linear\_model (line 361)  
steady;

Error in dynare (line 233)  
evalin(‘base’,fname) ;

Error in Untitled2 (line 3)  
dynare linear\_model.mod

Can you please help me how to solve this problem.  
Thanking in anticipation.

[linear\_model.mod](https://forum.dynare.org/uploads/short-url/oqCnT67IWH1KqyuhAOWL4HXp4s.mod) (7.2 KB)

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [6 December 2020 08:33 UTC](https://forum.dynare.org/t/how-to-write-a-function-which-include-integral-sign-inside-the-function/16381/15 "2020-12-06T08:33:07Z")

</div>

Your linearization must be incorrect. Why are there constant terms showing up in your equations? E.g. in equation 3, why is there an `A` with value 0.75?

---

<div class="post-metadata">

**Author:** ![Goher](https://forum.dynare.org/letter_avatar_proxy/v4/letter/g/b9e5f3/32.png) [@Goher](https://forum.dynare.org/u/Goher)\
**Post date:** [7 December 2020 20:38 UTC](https://forum.dynare.org/t/how-to-write-a-function-which-include-integral-sign-inside-the-function/16381/16 "2020-12-07T20:38:38Z")

</div>

Thank you for your reply. Yes the value of A was incorrect as it is 1.00 but i think linearization of equation 3 is correct as this is production function and A is aggregate productivity. I put the correct value of A and now i have this error  
The steadystate file did not compute the steady state

Error in steady (line 104)  
print\_info(info,options\_.noprint, options\_);

Error in linear\_model (line 360)  
steady;

Error in dynare (line 233)  
evalin(‘base’,fname) ;

Error in Untitled2 (line 3)  
dynare linear\_model.mod

. Can you please tell me what is this error and also can you please tell me that rest of format of the model is correct? I am attaching fresh file herewith[linear\_model.mod](https://forum.dynare.org/uploads/short-url/rhRo17UCCbsBji5zphnnRMfEWeJ.mod) (7.2 KB)

thanking in anticipation

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [7 December 2020 21:40 UTC](https://forum.dynare.org/t/how-to-write-a-function-which-include-integral-sign-inside-the-function/16381/17 "2020-12-07T21:40:37Z")

</div>

Again, you are not doing the linearization correctly. You consistently need all constants or should drop all constant terms.
