# Heterogeneity error

**URL:** <https://forum.dynare.org/t/heterogeneity-error/28322>\
**Category:** Heterogeneity\
**Created:** [27 March 2026 12:44 UTC](https://forum.dynare.org/t/heterogeneity-error/28322 "2026-03-27T12:44:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ey2d](https://forum.dynare.org/letter_avatar_proxy/v4/letter/e/9dc877/32.png) [@ey2d](https://forum.dynare.org/u/ey2d)\
**Post date:** [27 March 2026 12:44 UTC](https://forum.dynare.org/t/heterogeneity-error/28322/1 "2026-03-27T12:44:41Z")

</div>

the preprocessor is giving me an error saying that q is not used in the model block, but it is present in the heterogeneity model block:

```auto
// Declare heterogeneity dimension

heterogeneity_dimension households;

// Household-level variables

var(heterogeneity=households)

   c (long_name = 'consumption')

   a (long_name = 'assets')

;

// Household-level shocks

varexo(heterogeneity=households)

   e (long_name = 'idiosyncratic efficiency')

;

// Aggregate variables

var

   q (long_name = 'Real bond price')

   Z (long_name = 'Aggregate endowment')

;

// Aggregate shocks

varexo

   eps_Z (long_name = 'Aggregate endowment shock')

;

// Parameters

parameters

   beta (long_name = 'Discount factor')

   eis (long_name = 'Elasticity of intertemporal substitution')

   rhoZ (long_name = 'Persistence of aggregate endowment shock')

;

eis = 0.5;

beta = 0.99;

rhoZ = 0.95;

verbatim;

initial_guess = struct;

initial_guess.agg.q = 1/beta*1.01;

rho_e = 0.966;

sig_e = 0.5;

[grid_e, ~, Pi_e] = rouwenhorst(rho_e, sig_e, 15, 1e-12, 1e5);

initial_guess.shocks.grids.e = grid_e;

initial_guess.shocks.Pi.e = Pi_e;

grid_a = logspace(log10(0.25), log10(200.25), 30)-0.25-0.25;

initial_guess.pol.grids.a = grid_a;

c = 0.1*(grid_a+grid_e);

a = grid_a+grid_e-c;

initial_guess.pol.values.c = c;

initial_guess.pol.values.a = a;

initial_guess.pol.order = {'e', 'a'};

end;

// Household optimization problem

model(heterogeneity=households);

   [name='Euler equation with borrowing constraint']

   beta * c(+1)^(-1/eis) - q * c^(-1/eis) = 0 ⟂ a >= -0.25;

[name='Budget constraint']

   a(-1) + Z * e - c - q * a = 0;

end;

// Aggregate equilibrium conditions

model;

   [name='Asset market clearing']

   SUM(a) = 0;

   [name='Aggregate shock process']

   log(Z) = rhoZ*log(Z(-1))+eps_Z;

end;

// Aggregate shock specification

shocks;

    var eps_Z; stderr 0.01;

end;

```

---

<div class="post-metadata">

**Author:** ![normann](https://forum.dynare.org/letter_avatar_proxy/v4/letter/n/b38774/32.png) [@normann](https://forum.dynare.org/u/normann)\
**Post date:** [30 March 2026 10:17 UTC](https://forum.dynare.org/t/heterogeneity-error/28322/2 "2026-03-30T10:17:44Z")

</div>

Hello @ey2d,

Thanks a lot for the report. This is a confirmed bug in the preprocessor. You may follow the issue I’ve created [here](https://git.dynare.org/Dynare/preprocessor/-/issues/145) in the preprocessor repo.

The preprocessor currently requires that all `var` and `varexo` variables appear in the aggregate `model` block. In your case, `q` only appears in the `model(heterogeneity=households)` block, which triggers the error. However, your model is perfectly valid: `q` is an endogenous aggregate variable that is implicitly pinned down by the asset market clearing condition `SUM(a) = 0`, through its effect on household savings decisions in the heterogeneous block.

There is unfortunately no workaround for this. Moving `q` to `parameters` or `varexo` breaks the equation-variable count or the economic logic, and adding a redundant equation for `q` in the aggregate block overspecifies the system.

We will fix this in the preprocessor so that it accepts aggregate variables appearing only in the heterogeneous model block, as long as the overall equation-variable count is balanced.

I’ll post a message in this thread when I’m done fixing the bug.

Thanks again,

Best regards,

Normann

---

<div class="post-metadata">

**Author:** ![ey2d](https://forum.dynare.org/letter_avatar_proxy/v4/letter/e/9dc877/32.png) [@ey2d](https://forum.dynare.org/u/ey2d)\
**Post date:** [30 March 2026 14:51 UTC](https://forum.dynare.org/t/heterogeneity-error/28322/3 "2026-03-30T14:51:04Z")

</div>

Thanks! It was driving me crazy wondering what I had done wrong.

---

<div class="post-metadata">

**Author:** ![normann](https://forum.dynare.org/letter_avatar_proxy/v4/letter/n/b38774/32.png) [@normann](https://forum.dynare.org/u/normann)\
**Post date:** [30 March 2026 15:12 UTC](https://forum.dynare.org/t/heterogeneity-error/28322/4 "2026-03-30T15:12:53Z")

</div>

Hello @ey2d,  
I’ve pushed a fix on my fork of the preprocessor if you don’t want to wait for a new minor release for the bug fix. You may find the associated branch [here](https://git.dynare.org/normann/preprocessor/-/tree/het-model-agg-vars-bug-fix).  
Best regards,  
Normann

---

<div class="post-metadata">

**Author:** ![ey2d](https://forum.dynare.org/letter_avatar_proxy/v4/letter/e/9dc877/32.png) [@ey2d](https://forum.dynare.org/u/ey2d)\
**Post date:** [30 March 2026 16:00 UTC](https://forum.dynare.org/t/heterogeneity-error/28322/5 "2026-03-30T16:00:52Z")

</div>

I am not clear on exactly what I need to do with the modified files. Would you mind giving me some detailed instructions?

---

<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:** [31 March 2026 11:20 UTC](https://forum.dynare.org/t/heterogeneity-error/28322/6 "2026-03-31T11:20:29Z")

</div>

At [Pipeline #14681 · Normann Rion / preprocessor · GitLab](https://git.dynare.org/normann/preprocessor/-/pipelines/14681) you can download the artifacts containing the relevant preprocessor binary for your system.

---

<div class="post-metadata">

**Author:** ![ey2d](https://forum.dynare.org/letter_avatar_proxy/v4/letter/e/9dc877/32.png) [@ey2d](https://forum.dynare.org/u/ey2d)\
**Post date:** [1 April 2026 14:04 UTC](https://forum.dynare.org/t/heterogeneity-error/28322/7 "2026-04-01T14:04:28Z")

</div>

Thanks, do I just replace the old preprocessor file or is there something else I need to do? Sorry for the endless questions.

---

<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:** [1 April 2026 17:35 UTC](https://forum.dynare.org/t/heterogeneity-error/28322/8 "2026-04-01T17:35:00Z")

</div>

If you are on Windows, yes: just replace the `dynare-preprocessor.exe` with the one from the artifacts.
