# Problems trying to compute Ramsey Policy

**URL:** <https://forum.dynare.org/t/problems-trying-to-compute-ramsey-policy/14087>\
**Category:** Optimal Policy\
**Created:** [3 July 2019 12:29 UTC](https://forum.dynare.org/t/problems-trying-to-compute-ramsey-policy/14087 "2019-07-03T12:29:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmalmi](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@mmalmi](https://forum.dynare.org/u/mmalmi)\
**Post date:** [3 July 2019 12:29 UTC](https://forum.dynare.org/t/problems-trying-to-compute-ramsey-policy/14087/1 "2019-07-03T12:29:28Z")

</div>

Hello everyone,

I am trying to compute Ramsey policy but I have to problems with this. First, the planner objective has habits on consumption so I need to run…

```auto
planner_objective((log(cons - hcons*cons(-1)) - lpsi*((lab^(1+vartheta))/(1+vartheta))));
ramsey_policy(planner_discount=0.99,order=1);

```

and I get the error:

> ERROR: Leads and lags on variables are forbidden in ‘planner\_objective’  
> Is there a way of introducing lags in the planner objective? If not, how can I get an equivalent function?

Second, does anyone know whether it is possible to compute ramsey policy in Dynare for a model that uses external funtions? When I change the objetive equation to avoid the lags problem and use this command

```auto
planner_objective((log(cons - hcons*cons) - lpsi*((lab^(1+vartheta))/(1+vartheta))));
ramsey_policy(planner_discount=0.99,order=1);

```

I get this new error:

> ERROR: third order derivatives of external functions are not implemented

Thank you for your help!  
M

---

<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:** [4 July 2019 08:02 UTC](https://forum.dynare.org/t/problems-trying-to-compute-ramsey-policy/14087/2 "2019-07-04T08:02:45Z")

</div>

Regarding the second error, I would need to see the file. Regarding the first issue: you can circumvent the problem by defining a lagged variable in the model:

`cons_lag=cons(-1)`  
and then writing the objective as

```auto
planner_objective((log(cons - hcons*cons_lag) - lpsi*((lab^(1+vartheta))/(1+vartheta))));

```

---

<div class="post-metadata">

**Author:** ![mmalmi](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@mmalmi](https://forum.dynare.org/u/mmalmi)\
**Post date:** [4 July 2019 11:39 UTC](https://forum.dynare.org/t/problems-trying-to-compute-ramsey-policy/14087/3 "2019-07-04T11:39:01Z")

</div>

Hello jpfeifer,

I attach here the mod-file.

[MMwelfare2.mod](https://forum.dynare.org/uploads/short-url/oSY4hXAUQ8YENeVi8HZnJlmGQDz.mod) (33.9 KB)

[paramfileopenMPRUBOTH.mat](https://forum.dynare.org/uploads/short-url/hP3Mxi4eeqno8DkRU2dADlDSSpF.mat) (8.8 KB)

Thank you very much

---

<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:** [4 July 2019 12:17 UTC](https://forum.dynare.org/t/problems-trying-to-compute-ramsey-policy/14087/4 "2019-07-04T12:17:55Z")

</div>

This is a limitation of Dynare, see [https://git.dynare.org/Dynare/dynare/issues/300](https://git.dynare.org/Dynare/dynare/issues/300)  
You are calling external functions and for this optimal policy problem, the third derivatives would be required.

---

<div class="post-metadata">

**Author:** ![mmalmi](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@mmalmi](https://forum.dynare.org/u/mmalmi)\
**Post date:** [4 July 2019 12:44 UTC](https://forum.dynare.org/t/problems-trying-to-compute-ramsey-policy/14087/5 "2019-07-04T12:44:21Z")

</div>

Ok. So the only way would be then to compute the third derivatives by hand and then indicate to dynare in some way which they are, right? or is there an alternative?

---

<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:** [4 July 2019 13:01 UTC](https://forum.dynare.org/t/problems-trying-to-compute-ramsey-policy/14087/6 "2019-07-04T13:01:38Z")

</div>

As far as I can see, there is no reason to use external functions. You can use Dynare’s builtin function for the Gaussian PDF and CDF, e.g.:

```auto
Fwbar = log(normcdf(omega,-(1/2)*(sig^2),sig));
Fwbarw = log(normpdf(omega,-(1/2)*(sig^2),sig));

```
