Heterogeneity error

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:

// 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;

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 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

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

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.
Best regards,
Normann

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

At Pipeline #14681 · Normann Rion / preprocessor · GitLab you can download the artifacts containing the relevant preprocessor binary for your system.