# Loop over permanent shocks

**URL:** <https://forum.dynare.org/t/loop-over-permanent-shocks/12507>\
**Category:** Estimation\
**Created:** [28 September 2018 09:29 UTC](https://forum.dynare.org/t/loop-over-permanent-shocks/12507 "2018-09-28T09:29:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![JTang](https://forum.dynare.org/letter_avatar_proxy/v4/letter/j/b19c9b/32.png) [@JTang](https://forum.dynare.org/u/JTang)\
**Post date:** [28 September 2018 09:29 UTC](https://forum.dynare.org/t/loop-over-permanent-shocks/12507/1 "2018-09-28T09:29:19Z")

</div>

Hi,

I am estimating permanent shocks in a perfect foresight model by fitting the model to the data.

Is there any command like set\_param\_value that I can use to reset the shock variables (or exogenous variables)? I have tried to assign new values to oo\_.endo\_simul, but it didn’t work. (which I mean the computed deterministic path didn’t change after the assignment of values. )

Or can I allow some parameters to enter shock blocks such that I can go back to use set\_param\_value?

Really appreciate it if anyone could offer me some suggestions!

---

<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:** [28 September 2018 10:26 UTC](https://forum.dynare.org/t/loop-over-permanent-shocks/12507/2 "2018-09-28T10:26:42Z")

</div>

Hi, the necessary approach has been discussed in

> [@Optimal Monetary Policy with nonlinear loss function](https://forum.dynare.org/t/optimal-monetary-policy-with-nonlinear-loss-function/5951/15):
>
> Just set the respective entry in oo\_.exo\_simul in the loop and then call perfect\_foresight\_solver

---

<div class="post-metadata">

**Author:** ![JTang](https://forum.dynare.org/letter_avatar_proxy/v4/letter/j/b19c9b/32.png) [@JTang](https://forum.dynare.org/u/JTang)\
**Post date:** [29 September 2018 02:57 UTC](https://forum.dynare.org/t/loop-over-permanent-shocks/12507/3 "2018-09-29T02:57:08Z")

</div>

Hi Professor:

Thank you very much for your reply! Your suggestion is most helpful. I had set the entry in oo\_.exo\_simul before calling perfect\_foresight\_setup. I guess it was where the problem came from.

Thanks once again!

---

<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:** [30 September 2018 13:12 UTC](https://forum.dynare.org/t/loop-over-permanent-shocks/12507/4 "2018-09-30T13:12:10Z")

</div>

Yes, because

```auto
perfect_foresight_setup

```

will reconstruct

```auto
oo_.exo_simul 

```

from the blocks you specified.

---

<div class="post-metadata">

**Author:** ![JTang](https://forum.dynare.org/letter_avatar_proxy/v4/letter/j/b19c9b/32.png) [@JTang](https://forum.dynare.org/u/JTang)\
**Post date:** [2 October 2018 05:01 UTC](https://forum.dynare.org/t/loop-over-permanent-shocks/12507/5 "2018-10-02T05:01:48Z")

</div>

I see. Thank you so much for the explanation!

---

<div class="post-metadata">

**Author:** ![JTang](https://forum.dynare.org/letter_avatar_proxy/v4/letter/j/b19c9b/32.png) [@JTang](https://forum.dynare.org/u/JTang)\
**Post date:** [9 December 2020 13:41 UTC](https://forum.dynare.org/t/loop-over-permanent-shocks/12507/6 "2020-12-09T13:41:21Z")

</div>

Hi Professor:

I am using matlab optimization routines to loop over a parameter to optimize the value function in a deterministic model. In each loop, it calls `perfect_foresight_solver`.

Q1: `fmincon` did not give the right value. In the first loop (initial value that I gave), dynare turns to `homotopy` and successfully solve the path. Then `fmincon` just took it as the answer. When I changed the initial guess, this happened again. Why is the case? It doesn’t happen to `fminsearch`. But I do need to set a bound for the parameter.

Q2: Where is the `option` inside `perfect_foresight_solver` stored? I want to change `maxit` and `no_homotopy` settings mannually in different cases.

Thanks 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:** [9 December 2020 13:49 UTC](https://forum.dynare.org/t/loop-over-permanent-shocks/12507/7 "2020-12-09T13:49:56Z")

</div>

1. This sounds as if you are not conditioning on whether the simulation was succesful, i.e. ` oo_.deterministic_simulation.status == 1`
2. `options_.no_homotopy` and `options.simul.maxit`

---

<div class="post-metadata">

**Author:** ![JTang](https://forum.dynare.org/letter_avatar_proxy/v4/letter/j/b19c9b/32.png) [@JTang](https://forum.dynare.org/u/JTang)\
**Post date:** [9 December 2020 14:03 UTC](https://forum.dynare.org/t/loop-over-permanent-shocks/12507/8 "2020-12-09T14:03:14Z")

</div>

I set the value to be zero if `oo_.deterministic_simulation.status ~= 1` in the called function. Is this what you suggested? The problem still exists. Each time `fmincon` just reports the initial guess that I gave. Thanks!

---

<div class="post-metadata">

**Author:** ![JTang](https://forum.dynare.org/letter_avatar_proxy/v4/letter/j/b19c9b/32.png) [@JTang](https://forum.dynare.org/u/JTang)\
**Post date:** [9 December 2020 14:21 UTC](https://forum.dynare.org/t/loop-over-permanent-shocks/12507/9 "2020-12-09T14:21:13Z")

</div>

I also changed the `Algorithm` for `fmincon` to `sqp`, and it doesn’t work either. Attached are the log information under two cases: initial guess is -10 and -5. `fmincon` admits both are local optimum. The bound is between -200 and 0. The correct number should be around -200, a corner solution, indicated by a rough grid search.

[initial = -5.txt](https://forum.dynare.org/uploads/short-url/wA9utVngnrpnjDqZFeC8O3tPJVU.txt) (3.1 KB)  
[initial = -10.txt](https://forum.dynare.org/uploads/short-url/bTcHC6agsb2UhMSYsxDN6Ib7xEf.txt) (3.1 KB)

Thanks a lot!
