Skip to content
Snippets Groups Projects

:bug: Fix the derivative computations w.r.t heterogeneous exogenous variables

Merged Normann Rion requested to merge normann/preprocessor:het_exo into master

In models with heterogeneity, the preprocessor was failing to compute non-zero derivatives with respect to heterogeneous exogenous variables. Specifically, with a mod file like:

heterogeneity_dimension households;

var(heterogeneity=households) 
    e  // Idiosyncratic (log-)efficiency
;

varexo(heterogeneity=households) eps_e; // Idiosyncratic efficiency shock

var
    Z // Aggregate productivity
;
varexo eps_Z; // Aggregate productivity shock

parameters
    rho_e // Earning shock persistence
    sig_e // Earning shock innovation std err
    rho_Z // Aggregate TFP shock persistence
    sig_Z // Aggregate TFP shock innovation std err
    Z_ss  // Aggregate TFP shock average value
;

model(heterogeneity=households);
    log(e) - rho_e*log(e(-1)) - eps_e;
end;

model;
    log(Z) - rho_Z*log(Z(-1)) - (1-rho_Z)*log(Z_ss) - eps_Z;
end;

rho_e = 0.966;
sig_e = 0.5*sqrt(1-rho_e^2);
rho_Z = 0.8;
sig_Z = 0.014;
Z_ss = 0.8816;

shocks(heterogeneity=households);
    var eps_e; stderr sig_e;
end;

shocks;
    var eps_Z; stderr sig_Z;
end;

although eps_e (declared as varexo(heterogeneity=households) eps_e;) appears explicitly in the equation, its derivative with respect to itself was incorrectly set to zero in the generated dynamic model file. This did not occur for standard exogenous variables (like eps_Z in the aggregate block), whose derivatives were handled correctly. The root cause seemed to be that VariableNode::prepareForDerivation() did not register variables of type SymbolType::heterogeneousExogenous as differentiable. As a result, although the variable appeared in the model, it was missing from the non_null_derivatives set. This caused any derivative computation w.r.t. that variable to silently return zero. VariableNode::computeDerivative was not returning a proper result for variables of type SymbolType::heterogeneousExogenous either.

Edited by Normann Rion

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
Please register or sign in to reply
Loading