# Occbin: "increase maxit or check\_ahead\_periods" with very high maxit and check\_ahead\_periods

**URL:** <https://forum.dynare.org/t/occbin-increase-maxit-or-check-ahead-periods-with-very-high-maxit-and-check-ahead-periods/20245>\
**Category:** Occbin\
**Created:** [29 April 2022 15:34 UTC](https://forum.dynare.org/t/occbin-increase-maxit-or-check-ahead-periods-with-very-high-maxit-and-check-ahead-periods/20245 "2022-04-29T15:34:42Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jrs28](https://forum.dynare.org/letter_avatar_proxy/v4/letter/j/7bcc69/32.png) [@Jrs28](https://forum.dynare.org/u/Jrs28)\
**Post date:** [29 April 2022 15:34 UTC](https://forum.dynare.org/t/occbin-increase-maxit-or-check-ahead-periods-with-very-high-maxit-and-check-ahead-periods/20245/1 "2022-04-29T15:34:42Z")

</div>

Hello,

I am receiving a persistent error when estimating a medium-scale DSGE model using Occbin. I am asked to increase check\_ahead\_periods despite already having set this to a comically high number (20000 quarters). I suspect from previous forum posts that this error is linked to the fact I need “periodic\_solution” set as well.

Here is the Occbin setup and estimation call:

```auto
    model;
        // interest and QE rules
        [name='interest', bind='ELB']
        iSR = 0.001247663;
        [name='interest', relax='ELB']
        iSR = iT - 1e-06*vr_s1*Ups;
    end;

    occbin_constraints;
        name 'ELB'; bind iT - 1e-06*vr_s1*Ups < 0.001247663; relax iT - 1e-06*vr_s1*Ups > 0.001247663;
    end;

    occbin_setup(likelihood_max_kalman_iterations = 100, likelihood_check_ahead_periods = 20000, smoother_maxit = 100, smoother_periods = 20000, likelihood_periodic_solution, smoother_periodic_solution);

    estimation(datafile=data_Hamilton, mode_compute = 6, mh_nblocks = 2, mh_replic = 20000, mode_check, smoother_redux) y iSR;

```

iSR is the actual interest rate, iT - 1e-06_vr\_s1_Ups is the shadow rate.

Is there any obvious reason why this might be wrong? I haven’t attached my modfile/code as it is split across seven or eight seperate files, but I can do so if necessary. My model does not have any unit roots (as confirmed by eigenvalues and the check command), but does exhibit very high shock persistence (one important shock decays by about 0.9% per period). It is also worth noting that in my observational data, the interest rate is stuck at the ELB for about 50 quarters (reflecting the UK 2008-2019), which I guess is an unusually long time for Occbin to stay in the alternative regime.

Many thanks in advance.

---

<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:** [29 April 2022 20:13 UTC](https://forum.dynare.org/t/occbin-increase-maxit-or-check-ahead-periods-with-very-high-maxit-and-check-ahead-periods/20245/2 "2022-04-29T20:13:35Z")

</div>

@rattoma Do you have an idea? In any case, we would need to see the files. You can try to use the `savemacro=filename`-command line option to create one mod-file containing all the code pieces.

---

<div class="post-metadata">

**Author:** ![Jrs28](https://forum.dynare.org/letter_avatar_proxy/v4/letter/j/7bcc69/32.png) [@Jrs28](https://forum.dynare.org/u/Jrs28)\
**Post date:** [2 May 2022 09:02 UTC](https://forum.dynare.org/t/occbin-increase-maxit-or-check-ahead-periods-with-very-high-maxit-and-check-ahead-periods/20245/3 "2022-05-02T09:02:47Z")

</div>

Thanks - here is the combined modfile, steady state files, and the data.

[PH\_COMB.mod](https://forum.dynare.org/uploads/short-url/w1YoKFUEtTaVdYChDbyvnRMqtAk.mod) (13.7 KB)  
[PH\_COMB\_steadystate.m](https://forum.dynare.org/uploads/short-url/2EVF3hiwgyMoVjM37wSTHventqG.m) (3.2 KB)  
[PH\_steadystate\_sublevel.m](https://forum.dynare.org/uploads/short-url/rWxy7ogHo4Dsk9mggKAsm8uO3EC.m) (3.3 KB)  
[data\_Hamilton.csv](https://forum.dynare.org/uploads/short-url/wM8LG17CQNLL3c4fSrIQmxMcWFu.csv) (8.7 KB)

---

<div class="post-metadata">

**Author:** ![rattoma](https://forum.dynare.org/letter_avatar_proxy/v4/letter/r/7ba0ec/32.png) [@rattoma](https://forum.dynare.org/u/rattoma)\
**Post date:** [2 May 2022 09:04 UTC](https://forum.dynare.org/t/occbin-increase-maxit-or-check-ahead-periods-with-very-high-maxit-and-check-ahead-periods/20245/4 "2022-05-02T09:04:27Z")

</div>

thank you. I will have a look, but it will not be so fast (I am a bit under water).

---

<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:** [11 May 2022 10:59 UTC](https://forum.dynare.org/t/occbin-increase-maxit-or-check-ahead-periods-with-very-high-maxit-and-check-ahead-periods/20245/5 "2022-05-11T10:59:55Z")

</div>

@Jrs28 I cannot run your main file due to `pars` not being defined.

---

<div class="post-metadata">

**Author:** ![Jrs28](https://forum.dynare.org/letter_avatar_proxy/v4/letter/j/7bcc69/32.png) [@Jrs28](https://forum.dynare.org/u/Jrs28)\
**Post date:** [11 May 2022 15:18 UTC](https://forum.dynare.org/t/occbin-increase-maxit-or-check-ahead-periods-with-very-high-maxit-and-check-ahead-periods/20245/6 "2022-05-11T15:18:35Z")

</div>

Apologies - I’ve tested the attached set of files, and they should work.

[data\_Hamilton.csv](https://forum.dynare.org/uploads/short-url/wM8LG17CQNLL3c4fSrIQmxMcWFu.csv) (8.7 KB)  
[PH\_COMB\_steadystate.m](https://forum.dynare.org/uploads/short-url/tKsrOP0MWXAo72d3sSy8MzsDreW.m) (2.2 KB)

[PH\_COMB.mod](https://forum.dynare.org/uploads/short-url/6jAOUvD8rCQ7xgDgafLGCq0WA9v.mod) (14.0 KB)  
[cal\_s\_core.m](https://forum.dynare.org/uploads/short-url/n3942Xtjy683XEkOngLGcDIQ1zp.m) (313 Bytes)  
[PH\_COMB\_steadystate.m](https://forum.dynare.org/uploads/short-url/tKsrOP0MWXAo72d3sSy8MzsDreW.m) (2.2 KB)  
[PH\_steadystate\_sublevel.m](https://forum.dynare.org/uploads/short-url/rWxy7ogHo4Dsk9mggKAsm8uO3EC.m) (3.3 KB)  
[solve\_steady\_core.m](https://forum.dynare.org/uploads/short-url/2IEKg23KUO55TRvnzMK4YQhnpmW.m) (361 Bytes)  
[find\_string\_index.m](https://forum.dynare.org/uploads/short-url/zGXExDpYVy5e3c3fUOvn4UMELxC.m) (427 Bytes)

---

<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:** [12 May 2022 09:51 UTC](https://forum.dynare.org/t/occbin-increase-maxit-or-check-ahead-periods-with-very-high-maxit-and-check-ahead-periods/20245/7 "2022-05-12T09:51:39Z")

</div>

1. Part of the problem is a bug that will crash Occbin whenever something goes wrong. See [Provide error handling to piece-wise linear Kalman filter (#1854) · Issues · Dynare / dynare · GitLab](https://git.dynare.org/Dynare/dynare/-/issues/1854)
2. The other issue is your specification. You had

```auto
occbin_constraints;
    name 'ELB'; bind iT - 1e-06*vr_s1*Ups < 0.001247663; relax iT - 1e-06*vr_s1*Ups > 0.001247663;
end;

```

So the ZLB exactly binding will fall between the two regimes, creating oscillations.  
Using

```auto
% load OccBin 
occbin_constraints;
    name 'ELB'; bind iT - 1e-06*vr_s1*Ups <= 0.001247663-1e-8; relax iT - 1e-06*vr_s1*Ups > 0.001247663+1e-8;
end;

occbin_setup(likelihood_max_kalman_iterations = 100, likelihood_check_ahead_periods = 200, smoother_maxit = 100, likelihood_maxit = 100, smoother_periods = 200, simul_check_ahead_periods = 200);

```

seems to work. It introduces a slight numerical buffer to prevent spurious reversals.

---

<div class="post-metadata">

**Author:** ![Jrs28](https://forum.dynare.org/letter_avatar_proxy/v4/letter/j/7bcc69/32.png) [@Jrs28](https://forum.dynare.org/u/Jrs28)\
**Post date:** [12 May 2022 11:16 UTC](https://forum.dynare.org/t/occbin-increase-maxit-or-check-ahead-periods-with-very-high-maxit-and-check-ahead-periods/20245/8 "2022-05-12T11:16:04Z")

</div>

Thank you, that’s very helpful - I’ll give that a try and let you know if I run into any further difficulties.

---

<div class="post-metadata">

**Author:** ![Jrs28](https://forum.dynare.org/letter_avatar_proxy/v4/letter/j/7bcc69/32.png) [@Jrs28](https://forum.dynare.org/u/Jrs28)\
**Post date:** [12 May 2022 13:57 UTC](https://forum.dynare.org/t/occbin-increase-maxit-or-check-ahead-periods-with-very-high-maxit-and-check-ahead-periods/20245/9 "2022-05-12T13:57:38Z")

</div>

One further question - I see from pausing the estimation that Dynare is using the “missing\_observations\_kalman\_filter” despite the fact that my data is complete and not missing any observations. Is this the intended behaviour?

---

<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 May 2022 07:06 UTC](https://forum.dynare.org/t/occbin-increase-maxit-or-check-ahead-periods-with-very-high-maxit-and-check-ahead-periods/20245/10 "2022-05-13T07:06:50Z")

</div>

Yes, the piecewise-linear Kalman filter is attached to the `missing_observations_kalman_filter`.

---

<div class="post-metadata">

**Author:** ![Jrs28](https://forum.dynare.org/letter_avatar_proxy/v4/letter/j/7bcc69/32.png) [@Jrs28](https://forum.dynare.org/u/Jrs28)\
**Post date:** [18 May 2022 10:46 UTC](https://forum.dynare.org/t/occbin-increase-maxit-or-check-ahead-periods-with-very-high-maxit-and-check-ahead-periods/20245/11 "2022-05-18T10:46:52Z")

</div>

With regards to the error handling, there is an additional issue on line 357 of kalman\_update\_algo\_1.m. The subfunction occbin\_kalman\_update0 evaluates rank(F)\<size(F,1), which sometimes fails with NaN and causes a hard error. On my local copy of Dynare, I have added a try/catch circuit exactly as in model\_diagnostics.m lines 155-159 which appears (so far) to resolve the issue.

---

<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:** [19 May 2022 09:58 UTC](https://forum.dynare.org/t/occbin-increase-maxit-or-check-ahead-periods-with-very-high-maxit-and-check-ahead-periods/20245/12 "2022-05-19T09:58:43Z")

</div>

Thanks for pointing this out. My proposal is at [kalman\_update\_algo\_1.m: introduce error handling (!2032) · Merge requests · Dynare / dynare · GitLab](https://git.dynare.org/Dynare/dynare/-/merge_requests/2032)

---

<div class="post-metadata">

**Author:** ![Jrs28](https://forum.dynare.org/letter_avatar_proxy/v4/letter/j/7bcc69/32.png) [@Jrs28](https://forum.dynare.org/u/Jrs28)\
**Post date:** [27 May 2022 08:32 UTC](https://forum.dynare.org/t/occbin-increase-maxit-or-check-ahead-periods-with-very-high-maxit-and-check-ahead-periods/20245/13 "2022-05-27T08:32:07Z")

</div>

Thank you for the revised file. Unfortunately, there are still a couple of hard errors which get thrown:

- “Make shocks the right size for the output” (setting etahat) needs to be done before all the returns, not only that first try/catch loop. The reason is that etahat naturally has two columns, and is reduced using etahat = etahat(:,2) at the very end of the function. This reduction is not done if the function returns early.

- I also sometimes get an error “Error using missing\_observations\_kalman\_filter. Assignment between unlike types is not allowed.”. This seems to be a consequence the way that regimes\_ is initialised as [] at the beginning of the function. I have replaced the line regimes=[]; with regimes=[regimes0 regimes0(end)], which seems to have fixed the issue.

---

<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:** [27 May 2022 08:45 UTC](https://forum.dynare.org/t/occbin-increase-maxit-or-check-ahead-periods-with-very-high-maxit-and-check-ahead-periods/20245/14 "2022-05-27T08:45:32Z")

</div>

There is another set of updates pending: [Bug fixes for PKF (!2038) · Merge requests · Dynare / dynare · GitLab](https://git.dynare.org/Dynare/dynare/-/merge_requests/2038)

---

<div class="post-metadata">

**Author:** ![Jrs28](https://forum.dynare.org/letter_avatar_proxy/v4/letter/j/7bcc69/32.png) [@Jrs28](https://forum.dynare.org/u/Jrs28)\
**Post date:** [27 May 2022 09:05 UTC](https://forum.dynare.org/t/occbin-increase-maxit-or-check-ahead-periods-with-very-high-maxit-and-check-ahead-periods/20245/15 "2022-05-27T09:05:24Z")

</div>

Thanks, I’ll try that now.

---

<div class="post-metadata">

**Author:** ![wenzhuo](https://forum.dynare.org/letter_avatar_proxy/v4/letter/w/f9ae1b/32.png) [@wenzhuo](https://forum.dynare.org/u/wenzhuo)\
**Post date:** [16 April 2023 19:12 UTC](https://forum.dynare.org/t/occbin-increase-maxit-or-check-ahead-periods-with-very-high-maxit-and-check-ahead-periods/20245/17 "2023-04-16T19:12:24Z")

</div>

Dear Mr. Jpfeifer. Thank you very much.The second problem you pointed out also helped my model run successfully. What I want to ask is, is “bind iT - 1e-06_vr\_s1_Ups \<= 0.001247663-1e8” written by mistake? is it “bind iT - 1e-06_vr\_s1_Ups \<= 0.001247663-1e-8” that is correct?

---

<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:** [24 April 2023 12:04 UTC](https://forum.dynare.org/t/occbin-increase-maxit-or-check-ahead-periods-with-very-high-maxit-and-check-ahead-periods/20245/18 "2023-04-24T12:04:24Z")

</div>

Yes, that was a typo. I amended the reply above.

---

<div class="post-metadata">

**Author:** ![Econquer](https://forum.dynare.org/letter_avatar_proxy/v4/letter/e/ed8c4c/32.png) [@Econquer](https://forum.dynare.org/u/Econquer)\
**Post date:** [10 June 2025 17:02 UTC](https://forum.dynare.org/t/occbin-increase-maxit-or-check-ahead-periods-with-very-high-maxit-and-check-ahead-periods/20245/19 "2025-06-10T17:02:01Z")

</div>

Just a heads-up: This typo still seems to exist in the most recent version of the Dynare manual, where in section 4.14 it says

occbin\_constraints;  
name ‘ELB’; bind inom \<= iss-1e8; relax inom \> iss+1e-8;  
end;

---

<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:** [10 June 2025 20:07 UTC](https://forum.dynare.org/t/occbin-increase-maxit-or-check-ahead-periods-with-very-high-maxit-and-check-ahead-periods/20245/20 "2025-06-10T20:07:55Z")

</div>

Thanks for pointing this out. It will be fixed via [manual: fix mistake in example (!2365) · Merge requests · Dynare / dynare · GitLab](https://git.dynare.org/Dynare/dynare/-/merge_requests/2365)
