Getting Started: Krusell and Smith (1998)
The model describes a production economy with idiosyncratic uninsurable labor income risks faced by households. The aggregate shock is a shock to total factor productivity. The toolbox solves the steady state, and the deterministic linear/non-linear transition path after an unexpected aggregate shock. Following Boppart, Krusell and Mitman (2018) and Auclert et al. (2021), the deterministic transition path characterizes the first order effect of the aggregate shock.
We use the parameterization from Den Haan, Judd and Juillard (2010): Computational suite of models with heterogeneous agents: Incomplete markets and aggregate uncertainty. We also follow the notation in the paper.
HANS implements an optimization-based value function iteration approach to the individual problem. The current individual problem can also be solved by solving Euler equations with complementary slackness conditions (see the GDSGE example) or the endogenous grid method (see the implementation by the Sequence Space Jacobian toolbox).
The Model
Households are heterogeneous in their employment status \(e\in\{0,1\}\) and capital holding \(a \in R^+\). They solve the following Bellman equation:
where \(\bar{l}\) is the labor supply if being employed, \(\tau\) is the labor income tax rate, and \(\mu\) is the unemployment insurance payment rate. \(r_t\) and \(w_t\) are interest rate and wage rate, respectively. Households face a no-borrowing constraint \(a'\geq 0\).
Representative firms hire capital and labor and produce according to \(Y_t = Z_t K_t^{\alpha} L_t^{1-\alpha}\). Capital depreciates at rate \(\delta\). Interest and wage rates are competitively determined
Given an initial distribution over households’ states, \(\Phi_0\), a sequential competitive equilibrium is a sequence of (1) distribution over households’ states \(\{\Phi_t\}_{t=0}^{\infty}\), (2) households’ value and policy functions \(\{v_t,g_{c,t},g_{a',t}\}_{t=0}^{\infty}\), and (3) aggregate quantities and prices \(\{K_t, L_t, r_t, w_t\}_{t=0}^{\infty}\) such that
\(\{v_t,g_{c,t},g_{a',t}\}\) solve households’ decision problems defined by (1)
Market clearing: \(K_t=\int a \ \mathrm{d}\Phi_t(e,a)\), \(L_t=\int \bar{l} e \ \mathrm{d}\Phi_t(e,a)\). Goods market clearing implied by Walras’s law.
\(r_t\) and \(w_t\) are determined by (2).
Unemployment benefit is financed by labor income tax: \(w_t\int \bar{l} \tau e \ \mathrm{d}\Phi_t(e,a)=w_t\int (1-e)\mu \ \mathrm{d}\Phi_t(e,a)\).
\(\{\Phi_t\}\) are consistent with policy functions \(g_{a',t}\) and exogenous transitions of \(e\).
The Toolbox Script (hmod) File
The model can be represented using KS_JEDC10.hmod
, listed below.
1% The parameters are from from den Haan, Judd, Juillard, 2010, "Computational Suite of models with heterogeneous agents:
2% Incomplete markets and aggregate uncertainty" Journal of Economic Dynamics and Control, 34, pp 1 - 3.
3parameters beta r w;
4beta = 0.99; % subjective discount factor
5r = 0.009; % asset return
6w = 0.89; % wage rate
7labor = 1.0/0.9; % exogenous labor supply when working
8mu = 0.15; % unemployment insurance replacement ratio
9
10var_shock e;
11shock_trans = [0.600000, 0.400000;
12 0.044445, 0.955555];
13e = [0.00;1.00];
14shock_invariant_dist = [0.1;0.9];
15e_bar = shock_invariant_dist(:).'*e(:);
16L = labor*e_bar;
17unemp_rate = shock_invariant_dist(1); % unemployment rate
18tau = mu*unemp_rate/L; % labor income tax rate
19
20var_state a;
21a = exp(linspace(log(0.25), log(200 + 0.25), 500)) - 0.25;
22
23var_pre_vfi budget;
24budget = (1+r)*a + w*((1.0-tau)*e*labor + mu*(1- e));
25
26% var_policy defines the choice variable
27var_policy ap;
28initial ap 0.0;
29% var_aux defines varaibles that can be simply evaluated
30var_aux c;
31
32vfi;
33 c = budget - ap;
34 u = log(c);
35 Tv = u + beta*EXPECT(v(ap));
36 ap <= budget;
37 ap >= 0.0;
38end;
39
40var_agg K;
41K = 43.0; % initial guess
42alpha = 0.36; % capital share
43delta = 0.025; % depreciation
44
45var_agg_shock Z;
46Z = 1.0; % steady state value
47
48model;
49 % Aggregate conditions stated like Dynare
50 r = alpha * Z * K(-1)^(alpha-1) * L^(1-alpha) - delta;
51 w = (1-alpha) * Z * K(-1)^alpha * L^(-alpha);
52 K == ap; % asset demand = asset supply
53 % Allow box constraints for aggregate variables
54 K >= 38.0;
55 % post evaluation
56 Y = Z*(K(-1)^alpha)*(L^(1-alpha));
57 I = K - (1 - delta)*K(-1);
58 C = Y - I;
59end;
The goal of the script file is to define a vfi block (Value Function Iteration) that defines the individual decision problem, and a model block that defines the aggregate equilibrium conditions.
Information required for solving the individual problem needs to be defined before the vfi block. Blocks defining the information are explained in order.
1% The parameters are from from den Haan, Judd, Juillard, 2010, "Computational Suite of models with heterogeneous agents:
2% Incomplete markets and aggregate uncertainty" Journal of Economic Dynamics and Control, 34, pp 1 - 3.
3parameters beta r w;
4beta = 0.99; % subjective discount factor
5r = 0.009; % asset return
6w = 0.89; % wage rate
7labor = 1.0/0.9; % exogenous labor supply when working
8mu = 0.15; % unemployment insurance replacement ratio
This block defines parameters that are used in the vfi block and their values.
10var_shock e;
11shock_trans = [0.600000, 0.400000;
12 0.044445, 0.955555];
13e = [0.00;1.00];
14shock_invariant_dist = [0.1;0.9];
15e_bar = shock_invariant_dist(:).'*e(:);
16L = labor*e_bar;
17unemp_rate = shock_invariant_dist(1); % unemployment rate
18tau = mu*unemp_rate/L; % labor income tax rate
This block declares individual exogenous states in var_shock and specifies their values. They need to be defined as discrete Markov processes with joint transition matrix defined in shock_trans. Given the calibration of unemployment insurance payment \(\mu\), balanced-budget labor income tax rate \(\tau\) can be determined in advance.
20var_state a;
21a = exp(linspace(log(0.25), log(200 + 0.25), 500)) - 0.25;
This block declares individual endogenous states in var_state, and specifies the values of discretized grids over which the value and policy functions are approximated. For multi-dimension states, functions will be approximated over the tensor products of discretized state values.
23var_pre_vfi budget;
24budget = (1+r)*a + w*((1.0-tau)*e*labor + mu*(1- e));
This block defines variables that are simple functions of exogenous and/or endogenous states, which can be evaluated before solving the decision problem. Here, the budget is simply the sum of capital and labor income, evaluated at certain prices which are defined as parameters. This block is optional.
26% var_policy defines the choice variable
27var_policy ap;
28initial ap 0.0;
Variables that are to be optimized with (here, future capital holding \(a'\)) are declared as var_policy. Auxiliary variables (here, consumption \(c\)) that can be directly evaluated as simple functions of var_shock, var_state and/or var_policy are declared as var_aux.
With all information ready, the individual problem is defined in the vfi block enclosed by vfi; and end;.
32vfi;
33 c = budget - ap;
34 u = log(c);
35 Tv = u + beta*EXPECT(v(ap));
36 ap <= budget;
37 ap >= 0.0;
38end;
The vfi block starts from given values of var_state (here, \((e,a)\)) and var_policy (here, \(a'\)), to define an objective specified in Tv, in the line highlighted. As shown, this line has a natural syntax following the Bellman equation, where the future value function v is treated as known and called over future endogenous state values. The EXPECT operator is used to integrate over realizations of future exogenous states.
Box constraints for var_policy (here \(0 \leq a'\leq budget\)) and arbitrary equality or inequality constraints can be defined after the line that defines the objective.
All var_auxs (here, \(c\)) needs to be defined, and their values be accessed from the returned solution.
The script file can stop after defning the vfi block so the toolbox only generates code for solving the decision problem that is self-contained.
For solving the equilibrium, a system of equations for aggregate variables needs to be defined in the model block, with all required information defined before the block explained in order.
40var_agg K;
41K = 43.0; % initial guess
42alpha = 0.36; % capital share
43delta = 0.025; % depreciation
Unknowns of the equilibrium system needs to be declared as var_agg (here, \(K\)), with their initial values specified. Values of any parameters(here, \(\alpha,\delta\)) that are used in defining the aggregate system need to be specified.
45var_agg_shock Z;
46Z = 1.0; % steady state value
Aggregate shocks are declared as var_agg_shock. Aggregate shocks are essentially model parameters that are allowing to be time variant. Here is the aggregate TFP, \(Z\).
With all information ready, the aggregate equilibrium system is defined in
48model;
49 % Aggregate conditions stated like Dynare
50 r = alpha * Z * K(-1)^(alpha-1) * L^(1-alpha) - delta;
51 w = (1-alpha) * Z * K(-1)^alpha * L^(-alpha);
52 K == ap; % asset demand = asset supply
53 % Allow box constraints for aggregate variables
54 K >= 38.0;
55 % post evaluation
56 Y = Z*(K(-1)^alpha)*(L^(1-alpha));
57 I = K - (1 - delta)*K(-1);
58 C = Y - I;
59end;
The goal of the model block is to define the equation system that characterizes equilibrium conditions. Each equation is defined with “==”, as highlighted in the code block. Here, the system consists of a simple equation, asset market clearing, \(K_{t+1}=\int g_{a',t} d\Phi_t(e,a)\). var_policys can be used in the equation definition to represent the aggregates of individual policy functions integrated over the distribution at time \(t\), i.e., ap in the line represents \(\int g_{a',t} d\Phi_t(e,a)\) (recall \(ap\) is declared as one var_policy).
Before defining the system, intermediate variables, such as \(r,w\) are evaluated in order. Note that before defining the equation, parameters for solving individual decision problems need to be updated (here, \(r\), \(w\)) to respect the change in var_agg. For indexing time sequence of variables, the notation follows a convention of Dynare: the aggregate predetermined variables need to be indexed as lag variables (here, \(K(-1)\) that enters the evaluations of \(r\) and \(w\)).
Box constraints can be imposed for var_agg. Here \(K \geq 38\) is specfied so that \(r\) is bounded below to guarantee the convergence of value function iteration.
Other other aggregate equilibrium variables can be defined after the definition of equations (here, \(Y,I,C\) defined in the last three lines). The values of these variables will be returned after the system is solved.
Use the Toolbox
After parsing the script file, the toolbox generates MATLAB files: solve_vfi.m, solve_ss.m, solve_trans_linear.m, solve_trans_nonlinear.m and other functions that can be called to solve the steady state, stationary distribution, and transition paths of the model. The usages of these functions are illustrated below.
Parse .hmod Files
Solve the Stationary Equilibrium
Solve the Transition Path After A Temporay Shock
Solve the linearized transition path
Solve the nonlinear transition path
Solve the Transition Path After A Permanent Shock
Simulate Individual Samples
Simulate Individual Samples at the Stationary Distribution
Simulate Individual Samples Along the Transition Path
What’s Next?
Behind the scene: understand the details of the Algorithm.
Check the Toolbox API reference.
More examples:
McKay, Nakamura and Steinsson (2016) for a Heterogeneous-Agent New-Keynesian model for defining complex equilibrium conditions and handling nonlinearity
A discrete-time two-asset HANK model for handling portfolio choices
Khan and Thomas (2008) for handling non-convex adjustment costs and stochastic state transitions