Heterogeneous agents model code
View the Project on GitHub kritikhanna/ContractEnforcement-GE
This page contains full matlab code and explanations for the heterogeneous agents - occupational choices model I use to study income disparities across Indian states.
On this webpage, there are three types of files:
Matlab .m files are either function files (performing a small functionality of the code) or tester files (testing correctness these small functionalities). All function/tester files can be run independently.
Code is divided into sections (1) - (4).
Section (1) contains functions for solving the heterogeneous firm’s maximization problem
Section (2) contains the functions for solving the individual’s Static Occupational Choice Problem
Section (3) contains the functions for solving the individual’s dynamic asset choice problem
Section (4) contains the functions for solving the PE
Section (5) contains the functions for solving the GE
Section (6) contains the functions for calibrating the model
Parameters used in the model are defined here: Model Parameters
Functions Flowchart: Functions Flowchart
This function computes the constraint on renting of capital and corresponding optimal labor for all combinations of state of assets and productivity, based on degree of imperfect enforcement of contract. Uses 3 methods for computing constrained k,l : numerical, vectorized and taylor series
Fastest version speed: 0.865 s (a X z is 5X6)
Subfunctions: conkl_numerical.m
Testers:
Images from main function: Kconst_az.png , Lconst_az.png, taylor.png
Images from testers: plotconkl.png, plotconkl_a.png, plotconkl_z.png, plotconkl_phi.png Kconst_rw.png, Lconst_rw.png
This function computes the firm profit maximing choice of capital and labor (given the constraint on capital due to imperfect enforceability) for all states of assets and entrepreneurial productivity of individuals. Calls function con_kl.m for noting the constraint on capital and labor before solving the optimal k and l.
Fastest version speed: 0.609 s (a X z is 5X6)
Subfunctions: con_kl.m
Testers:
Images from main function: Optimum_k.png , Optimum_l.png, Optimum_2D.png
Images from testers: kstar_rw.png, lstar_rw.png
Determines the static occupational choice for an individual given their state of assets and productivity. Occupational choice is between worker and Entrepreneur. Takes optikl.m as input for computing profits as an entrepreneur, which is important to make the occupational choice. Generates 2 outputs: Optimal Occupational Choice and profit/wage earned.
Fastest version speed: 2.609 s (a X z is 5X6)
Subfunctions: optikl.m
Images from main function: OC2.png
Determines the static occupational choice between worker, formal firm owner and informal firm owner. Takes optikl.m as inputs for computing profits as an formal firm/informal firm owner which are important to make the occupational choice. Generates outputs: Optimal Occupational Choice and COH, capital and labor
Fastest version speed: 2.81 s (a X z is 5X6)
Subfunctions: optikl.m
Images from main function: OC3_nolaskills.png,OC3_laskills.png
Alternate informal defn: OC3_2.m
4 Occupational type with casual worker.
The aim of this part of the code is to solve the individual’s dynamic asset problem given wage and interest rates.
Individuals arrive in a period with accumulated assets and a persistent entrepreneurial productivity shock. They decide their occupational choice and the optimal savings to carry forward to the next period. Simulating the entrepreneurial productivity process and optimal choices for heterogeneous agents, the outcome of this problem is a joint steady state distribution of assets and productivity given the wage and interest rate.
This function evaluates the utility at each combination of current assets, entrepreneurial productivity and future assets a’ for a 2 OC model. Takes COH as input from OC2.m function.
Fastest version speed: 2.477 s (a X z is 5X6)
Subfunctions: OC2.m
This function evaluates the utility at each combination of current assets, entrepreneurial productivity, labor opportunity and future assets a’ for a 3 OC model. Takes COH as input from OC3 function.
Fastest version speed: 3.383 s (a X z X s is 5X6X2)
Subfunctions: OC3.m
This function solves the dynamic programming problem and generates the value function/policy function for a 2 OC model.
Fastest version speed: 2.594 s (a X z is 25X10)
Subfunctions: hhsave_util_2OC
Testers:
Images from main function: Valuefunction_3D.png,
Valuefunction_2D.png, Policyfunction.png, Consumption.png
With uneven denser grid for small asset choices : hhsave_VFI_3OC_powerspace.m
This function solves the dynamic programming problem and generates the value function/policy function for a 3 OC model.
Fastest version speed: 7.448 s (a X z is 6X5)
Subfunctions: hhsave_util_3OC
Testers:
Images from main function: Valuefunction_3D_0.png,Valuefunction_3D_1.png
Valuefunction_2D_0.png, Valuefunction_2D_1.png
Policyfunction_0.png,Policyfunction_1.png Consumption_0.png, Consumption_1.png
Solve Stationary Distribution of the 2 OC problem given wages and interest rates.
Solve Stationary Distribution of the 3 OC problem given wages and interest rates.
Solve for model outcomes including aggregate capital, labor demanded and supplied given interest rates and wages for 2 OC problem
Solve for model outcomes including aggregate capital, labor demanded and supplied given interest rates and wages for 3 OC problem
Tester: tester_PE_3OC
Computing statistics: Stats_PE
Solving model outcomes at General Equilibrium
Tester: tester_GE_3OC
Original Paper: Credit Contract Enforcement and Income Disparities across Indian States