| 1 |
heterogeneity_dimension households; |
| 2 |
|
| 3 |
var(heterogeneity=households) |
| 4 |
b |
| 5 |
a |
| 6 |
c |
| 7 |
Va |
| 8 |
Vb |
| 9 |
u |
| 10 |
; |
| 11 |
|
| 12 |
varexo(heterogeneity=households) |
| 13 |
e |
| 14 |
; |
| 15 |
|
| 16 |
var |
| 17 |
piw |
| 18 |
psiw |
| 19 |
rb |
| 20 |
ra |
| 21 |
tax |
| 22 |
i |
| 23 |
psip |
| 24 |
I |
| 25 |
Q |
| 26 |
w |
| 27 |
N |
| 28 |
K |
| 29 |
div |
| 30 |
p |
| 31 |
pi |
| 32 |
mc |
| 33 |
r |
| 34 |
Y |
| 35 |
; |
| 36 |
|
| 37 |
varexo |
| 38 |
rstar |
| 39 |
markup |
| 40 |
G |
| 41 |
beta |
| 42 |
Z |
| 43 |
rinv_shock |
| 44 |
markup_w |
| 45 |
; |
| 46 |
|
| 47 |
shocks; |
| 48 |
var rstar; stderr 0.01; |
| 49 |
var markup; stderr 0.01; |
| 50 |
var G; stderr 0.01; |
| 51 |
var beta; stderr 0.01; |
| 52 |
var Z; stderr 0.01; |
| 53 |
var rinv_shock; stderr 0.01; |
| 54 |
var markup_w; stderr 0.01; |
| 55 |
end; |
| 56 |
|
| 57 |
parameters |
| 58 |
kappap |
| 59 |
alpha |
| 60 |
epsI |
| 61 |
muw |
| 62 |
phi |
| 63 |
omega |
| 64 |
Bg |
| 65 |
pshare |
| 66 |
delta |
| 67 |
kappaw |
| 68 |
frisch |
| 69 |
mup |
| 70 |
vphi |
| 71 |
eis |
| 72 |
chi0 |
| 73 |
chi1 |
| 74 |
chi2 |
| 75 |
Z_ss |
| 76 |
beta_ss |
| 77 |
r_ss |
| 78 |
G_ss |
| 79 |
; |
| 80 |
|
| 81 |
|
| 82 |
model(heterogeneity=households); |
| 83 |
// Euler equations |
| 84 |
c^(-1/eis) - (beta_ss+beta) * Vb(+1) = 0 ⟂ b >= 0; |
| 85 |
c^(-1/eis)*(1 + chi1 * sign(a-(1+ra)*a(-1)) * (abs(a-(1+ra)*a(-1))/((1+ra)*a(-1)+chi0))^(chi2-1)) - (beta_ss+beta) * Va(+1) = 0 ⟂ a >= 0; |
| 86 |
|
| 87 |
// Budget constraint |
| 88 |
(1 + ra) * a(-1) + (1 + rb) * b(-1) - (chi1 / chi2) * abs(a-(1+ra)*a(-1))^chi2 * ((1+ra)*a(-1)+chi0)^(1-chi2) + (1-tax) * w * N * e - c - a - b; |
| 89 |
|
| 90 |
// Effective labor definition |
| 91 |
u = e * c^(-1/eis); |
| 92 |
|
| 93 |
// Envelope conditions |
| 94 |
Va = (1 + ra)*(1 - (chi1/chi2) * ( - chi2 * sign(a-(1+ra)*a(-1)) * (abs(a-(1+ra)*a(-1))/((1+ra)*a(-1)+chi0))^(chi2-1) + (1-chi2) * (abs(a-(1+ra)*a(-1))/((1+ra)*a(-1)+chi0))^chi2 )) * c^(-1/eis); |
| 95 |
Vb = (1 + rb) * c^(-1/eis); |
| 96 |
end; |
| 97 |
|
| 98 |
model; |
| 99 |
// NKPC |
| 100 |
kappap * (mc - 1 / mup) + Y(+1) / Y * log(1 + pi(+1)) / (1 + r(+1)) + markup - log(1 + pi); |
| 101 |
|
| 102 |
// Equity price |
| 103 |
div(+1) + p(+1) - p * (1 + r(+1)); |
| 104 |
|
| 105 |
// Production function |
| 106 |
N = (Y / (Z_ss+Z) / K(-1) ^ alpha) ^ (1 / (1 - alpha)); |
| 107 |
|
| 108 |
// Labor demand |
| 109 |
mc = w * N / (1 - alpha) / Y; |
| 110 |
|
| 111 |
// Tobin's Q |
| 112 |
(K / K(-1) - 1) / (delta * epsI) + 1 - Q; |
| 113 |
|
| 114 |
// Valuation equation |
| 115 |
alpha * (Z_ss+Z(+1)) * (N(+1) / K) ^ (1 - alpha) * mc(+1) - (K(+1) / K - |
| 116 |
(1 - delta) + (K(+1) / K - 1) ^ 2 / (2 * delta * epsI)) + K(+1) / K * Q(+1) - (1 + r(+1) + rinv_shock) * Q; |
| 117 |
|
| 118 |
// Price adjustment cost |
| 119 |
mup / (mup - 1) / 2 / kappap * log(1 + pi) ^ 2 * Y - psip; |
| 120 |
|
| 121 |
// Aggregate investment |
| 122 |
K - (1 - delta) * K(-1) + K(-1) * (K / K(-1) - 1) ^ 2 / (2 * delta * epsI) - I; |
| 123 |
|
| 124 |
// Resource constraint |
| 125 |
Y - w * N - I - psip - div; |
| 126 |
|
| 127 |
// Taylor rule |
| 128 |
rstar + r_ss + phi * pi - i; |
| 129 |
|
| 130 |
// Fiscal policy |
| 131 |
(r * Bg + G_ss + G) / w / N - tax; |
| 132 |
|
| 133 |
// Returns on liquid asset |
| 134 |
r - omega - rb; |
| 135 |
|
| 136 |
// Returns on illiquid asset |
| 137 |
pshare * (div + p) / p(-1) + (1 - pshare) * (1 + r) - 1 - ra; |
| 138 |
|
| 139 |
// Fisher equation |
| 140 |
1 + i(-1) - (1 + r) * (1 + pi); |
| 141 |
|
| 142 |
// Wage inflation |
| 143 |
(1 + pi) * w / w(-1) - 1 - piw; |
| 144 |
|
| 145 |
// Wage adjustment cost |
| 146 |
muw / (1 - muw) / 2 / kappaw * log(1 + piw) ^ 2 * N - psiw; |
| 147 |
|
| 148 |
// Wage NKPC |
| 149 |
kappaw * (vphi * N ^ (1 + 1 / frisch) - (1 - tax) * w * N * SUM(u) / muw) + (beta_ss+beta) * log(1 + piw(+1)) + markup_w - log(1 + piw); |
| 150 |
|
| 151 |
// Total asset market clearing |
| 152 |
p + Bg - SUM(b) - SUM(a); |
| 153 |
end; |
| 154 |
|
| 155 |
load 'hank_2a.mat'; |
| 156 |
|
| 157 |
param_names = fieldnames(steady_state.params); |
| 158 |
for i=1:numel(param_names) |
| 159 |
param = param_names{i}; |
| 160 |
set_param_value(param, steady_state.params.(param)); |
| 161 |
end |
| 162 |
|
| 163 |
% Initialize steady state once for all tests |
| 164 |
heterogeneity_load_steady_state(filename = hank_2a); |
| 165 |
assert(isfield(oo_, 'heterogeneity'), 'oo_.heterogeneity field missing'); |
| 166 |
assert(isfield(oo_.heterogeneity, 'steady_state'), 'oo_.heterogeneity.ss field missing'); |
| 167 |
assert(isfield(oo_.heterogeneity, 'sizes'), 'oo_.heterogeneity.sizes field missing'); |
| 168 |
assert(isfield(oo_.heterogeneity, 'mat'), 'oo_.heterogeneity.mat field missing'); |
| 169 |
assert(isfield(oo_.heterogeneity, 'indices'), 'oo_.heterogeneity.indices field missing'); |
| 170 |
|
| 171 |
% Solve once for all tests |
| 172 |
heterogeneity_solve; |
| 173 |
|
| 174 |
testFailed = 0; |
| 175 |
testResults = []; % Array to collect all test results |
| 176 |
|
| 177 |
verbatim; |
| 178 |
% Test heterogeneity.simulate function (reuse initialized and solved model) |
| 179 |
[testFailed, testResults] = test_simulate_stochastic(M_, options_, oo_, steady_state, testFailed, testResults); |
| 180 |
|
| 181 |
% Test permutation handling |
| 182 |
[testFailed, testResults] = test_permutation(M_, options_, oo_, steady_state, testFailed, testResults); |
| 183 |
|
| 184 |
% Print test summary |
| 185 |
print_test_summary(testResults); |
| 186 |
|
| 187 |
if testFailed > 0 |
| 188 |
error('Some unit tests failed!'); |
| 189 |
end |
| 190 |
end; |