| 1 |
heterogeneity_dimension households; |
| 2 |
|
| 3 |
var(heterogeneity=households) |
| 4 |
c // consumption |
| 5 |
n // labor supply |
| 6 |
ns // effective labor supply |
| 7 |
a // assets |
| 8 |
Va // derivative of value function w.r.t. a |
| 9 |
; |
| 10 |
|
| 11 |
varexo(heterogeneity=households) |
| 12 |
e // idiosyncratic efficiency |
| 13 |
; |
| 14 |
|
| 15 |
var |
| 16 |
Y L w pi Div Tax r |
| 17 |
; |
| 18 |
|
| 19 |
varexo G markup rstar; |
| 20 |
|
| 21 |
shocks; |
| 22 |
var G; stderr 0.01; |
| 23 |
var markup; stderr 0.01; |
| 24 |
var rstar; stderr 0.01; |
| 25 |
end; |
| 26 |
|
| 27 |
parameters |
| 28 |
beta vphi |
| 29 |
eis frisch |
| 30 |
rho_e sig_e |
| 31 |
rho_Z sig_Z |
| 32 |
mu kappa phi |
| 33 |
Z B r_ss |
| 34 |
; |
| 35 |
|
| 36 |
model(heterogeneity=households); |
| 37 |
// Euler equation with borrowing constraint |
| 38 |
c^(-1/eis) - beta * Va(+1) = 0 ⟂ a >= 0; |
| 39 |
|
| 40 |
// Budget constraint |
| 41 |
(1 + r) * a(-1) + w * n * e + (Div-Tax) * e - c - a; |
| 42 |
|
| 43 |
// Envelope condition |
| 44 |
Va = (1 + r) * c^(-1/eis); |
| 45 |
|
| 46 |
// Intratemporal FOC for labor supply |
| 47 |
vphi*n^(1/frisch) - w*e*c^(-1/eis); |
| 48 |
|
| 49 |
// Definition of the effective labor supply |
| 50 |
ns = n * e; |
| 51 |
end; |
| 52 |
|
| 53 |
model; |
| 54 |
// Firm |
| 55 |
L - Y / Z; |
| 56 |
Div - (Y - w * L - mu / (mu - 1) / (2 * kappa) * log(1 + pi)^2 * Y); |
| 57 |
|
| 58 |
// Monetary policy (Taylor rule) |
| 59 |
(1 + r_ss + rstar(-1) + phi * pi(-1)) / (1 + pi) - 1 - r; |
| 60 |
|
| 61 |
// Fiscal policy |
| 62 |
Tax - (r * B) - G; |
| 63 |
|
| 64 |
// NKPC |
| 65 |
kappa * (w / Z - 1 / mu) |
| 66 |
+ Y(+1)/Y * log(1 + pi(+1)) / (1 + r(+1)) |
| 67 |
+ markup |
| 68 |
- log(1 + pi); |
| 69 |
|
| 70 |
// Market clearing |
| 71 |
SUM(a) - B; // asset market |
| 72 |
sum(ns) - L; // labor market |
| 73 |
end; |
| 74 |
|
| 75 |
mat_file = 'hank_1a_ssj.mat'; |
| 76 |
if ~exist(mat_file, 'file') |
| 77 |
url = sprintf('https://dynare.org/test-data/%s', mat_file); |
| 78 |
websave(mat_file, url); |
| 79 |
end |
| 80 |
load(mat_file); |
| 81 |
|
| 82 |
param_names = fieldnames(steady_state.params); |
| 83 |
for i=1:numel(param_names) |
| 84 |
param = param_names{i}; |
| 85 |
set_param_value(param, steady_state.params.(param)); |
| 86 |
end |
| 87 |
|
| 88 |
% Initialize steady state once for all tests |
| 89 |
heterogeneity_load_steady_state(filename = hank_1a_ssj); |
| 90 |
|
| 91 |
% Solve once for all tests |
| 92 |
heterogeneity_solve; |
| 93 |
|
| 94 |
verbatim; |
| 95 |
testFailed = 0; |
| 96 |
testResults = []; % Array to collect all test results |
| 97 |
|
| 98 |
% Test the solve routine and SSJ comparisons (validation only) |
| 99 |
[testFailed, result] = run_test('heterogeneity.solve functionality and SSJ validation', @() test_solve_functionality(M_, oo_, G, true), testFailed); |
| 100 |
testResults = [testResults; result]; |
| 101 |
|
| 102 |
% Test the solve routine with custom impulse responses (calls solve with custom impulses) |
| 103 |
[testFailed, result] = run_test('heterogeneity.solve with custom impulse responses', @() test_solve_with_custom_impulse_responses(M_, options_, oo_, x_hat_dash, G, J, F, curlyDs, curlyYs, a_i, a_pi), testFailed); |
| 104 |
testResults = [testResults; result]; |
| 105 |
|
| 106 |
% Test heterogeneity.simulate function (reuse initialized and solved model) |
| 107 |
[testFailed, testResults] = test_simulate_stochastic(M_, options_, oo_, steady_state, testFailed, testResults); |
| 108 |
|
| 109 |
% Print test summary |
| 110 |
print_test_summary(testResults); |
| 111 |
|
| 112 |
if testFailed > 0 |
| 113 |
error('Some unit tests failed!'); |
| 114 |
end |
| 115 |
end; |