Preprocessor rejects aggregate variables that only appear in the heterogeneous model block
Ref: https://forum.dynare.org/t/heterogeneity-error/28322
Description
The preprocessor requires that all var and varexo variables appear in the aggregate model block. However, in heterogeneous agent models, an aggregate endogenous variable may legitimately appear only in the model(heterogeneity=...) block and be implicitly pinned down by an aggregate market-clearing condition through the household optimization.
Minimal example
var q Z;
varexo eps_Z;
model(heterogeneity=households);
beta * c(+1)^(-1/eis) - q * c^(-1/eis) = 0 ⟂ a >= -0.25;
a(-1) + Z * e - c - q * a = 0;
end;
model;
SUM(a) = 0;
log(Z) = rhoZ*log(Z(-1)) + eps_Z;
end;
This fails with:
Error: q not used in the model block
The variable q (the bond price) is endogenous and determined by the asset market clearing condition SUM(a) = 0. It does not need an explicit equation in the aggregate block because the SUM(a) residual depends on q through the household policy functions. There is no workaround: q cannot be moved to parameters (equation count mismatch) or varexo (it is endogenous), and adding a redundant equation like q = q_ss + e_q overspecifies the system.
Expected behavior
The preprocessor should accept aggregate var and varexo variables that appear only in the heterogeneous model block, provided the overall equation-variable count is balanced.