This is a work-in-progress Matlab package consisting of functions that solve the dynamic life cycle model in Nygård, Sørensen and Wang (Nygård, Sørensen and Wang 2020). The code companion presents solutions to the dynamic life-cycle problem, and methods for evaluating the marginal gains from allocating additional welfare checks. Tested with Matlab 2019a.
All functions are parts of a matlab toolbox that can be installed:
Download and install the Matlab toolbox: PrjOptiSNW.mltbx
The Code Companion can also be accessed via the bookdown site and PDF linked below:
This files below consists of a collection of mlx based vignettes for functions that are available from PrjOptiSNW. Each Vignette file contains various examples for invoking each function.
The package relies on MEconTools, which needs to be installed first. The package does not include allocation functions, only simulation code to generate the value of each welfare check increments for households. Allocation functions rely the R optimal allocation package PrjOptiAlloc.
From other repositories: For dynamic borrowing and savings problems, see Dynamic Asset Repository; For code examples, see also R Example Code, Matlab Example Code, and Stata Example Code; For intro stat with R, see Intro Statistics for Undergraduates, and intro Math with Matlab, see Intro Mathematics for Economists. See here for all of Fan's public repositories.
Please contact FanWangEcon for issues or problems.
In addition to downloading and installing PrjOptiSNW.mltbx, can also:
# Clone Package from Git Bash
cd "C:/Downloads"
git clone https://github.com/fanwangecon/PrjOptiSNW.git
Install the Package from inside Matlab:
# Install Matlab Toolbox PrjOptiSNW
toolboxFile = 'C:/Downloads/PrjOptiSNW/PrjOptiSNW.mltbx';
# toolboxFile = 'C:/Users/fan/PrjOptiSNW/PrjOptiSNW.mltbx';
agreeToLicense = true;
installedToolbox = matlab.addons.toolbox.installToolbox(toolboxFile, agreeToLicense)
- Household Problem and Distributions: mlx | m | pdf | html
- Summarize the household's dynamic programming problem and the distributions across heterogeneous households groups.
- Values of Checks Conditional on 2019 Information: mlx | m | pdf | html
- Summarize the computation of expecations relevant for planning objectives given information avaiable in 2019.
- The Welfare Check Planning Problem: mlx | m | pdf | html
- Summarize several allocation problem that condition allocations on income, marital status, the number of children less than 18, and possibly age.
- Model Parameters: mlx | m | pdf | html
- Model parameters, transition matrices, permanent heterogeneities.
- PrjOptiSNW: snw_mp_param()
- Model Controls Parameters: mlx | m | pdf | html
- Parameters to control display options etc.
- PrjOptiSNW: snw_mp_control()
- Policy and Value Functions Dynamic Life Cycle Vectorized Bisection: mlx | m | pdf | html
- Solving for policy and value functions from 18 to 100 years of age, at 1 year interval.
- Households face persistent productivity shocks for household heads, stochastic shocks for spousal income, exogenous children under age 17 transition probability, and age-specific household-head survival probabilities.
- The household can have up to four children under age 17, and has permanent heterogeneity in marital status and education types.
- Problem solved for exact savings choices using vectorized bisection from from MEconTools.
- PrjOptiSNW: snwx_vfi_bisec_vec()
- Small Test Looped Minimizer Routine to Solve for Exact Savings Choices: mlx | m | pdf | html
- Solve for the exact savings choices using matlab minimizer in an iterative loop.
- The code demonstrates the solution structure. We use snwx_vfi_bisec_vec() with vectorized bisection for working implementations.
- Due to speed, only show testing results at small grid without spousal shocks.
- PrjOptiSNW: snw_vfi_main()
- Small Test Looped over States Grid Search Solution: mlx | m | pdf | html
- The savings choice grid is the same as the savings states grid. Solve for optimal savings choices using grid-search. Loop over the state space, at each state-space point, vectorized optimization.
- Our problem requires very high precision to solve for the marginal gains to households from each increment of welfare checks. We rely on the exact solution method from snwx_vfi_bisec_vec() for the working code.
- Due to speed, only show testing results at small grid without spousal shocks.
- PrjOptiSNW: snw_vfi_main_grid_search()
- Small Test Vectorized Bisection Solve for Exact Savings Choices: mlx | m | pdf | html
- Vectorized bisection exact solution code tested with small grid to compare to alternative solutiom methods.
- Small grid without spousal shocks.
- PrjOptiSNW: snwx_vfi_bisec_vec()
- Small Test Spousal Shocks Test Vectorized Bisection Solve for Exact Savings Choices: mlx | m | pdf | html
- Vectorized bisection exact solution code tested with small grid to compare to alternative solutiom methods.
- Small grid with spousal shocks. There are three shocks: persistent household head income shock, i.i.d. spousal income shock, and persistent kids count transition shocks.
- PrjOptiSNW: snwx_vfi_bisec_vec()
- Policy and Value Functions Dynamic Life Cycle if Unemployed: mlx | m | pdf | html
- Solving the dynamic programming problem conditional on having an one period unemployment shock.
- There is an unemployment shock in 2020. We first solve for the policy and value functions without the unemployment shock.
- Using the value function from the world without the 2020 covid unemployment shock as future values, we solve for optimal choices in 2020 given a COVID unemployment shock.
- The COVID shock lowers the realization of household's stochastic income process proportionally, but the lost income might be replenished by unemployment benefits up to 100 percent. Unemployment benefits have to be paid for by taxes.
- PrjOptiSNW: snwx_vfi_bisec_vec()
- Assets and Demographic Distributions with Continuous Exact Savings Choices (Loop): mlx | m | pdf | html
- Simulate the life cycle distribution of assets, consumptions, and demographic patterns up to age 100, given exogenous initial distributions at age 18. Solves for budget clearing tax rates given distributional results. Uses vectorized bisection to solve for exact savings choices, looped distribution code.
- PrjOptiSNW: snw_ds_main()
- Assets and Demographic Distributions with Continuous Exact Savings Choices (Vectorized): mlx | m | pdf | html
- Simulate the life cycle distributions This is the fully vectorized version of snw_ds_main().
- PrjOptiSNW: snw_ds_main_vec()
- Assets and Demographic Distributions with Grid Search: mlx | m | pdf | html
- Grid search solution using grid search for savings choices, the savings state-space grid is the same as the savings choice-grid. Exact choice solution from snw_ds_main() generates significantly smoother distributions.
- PrjOptiSNW: snw_ds_main_grid_search()
- Marginal Gain Per Check 2020 Employed: mlx | m | pdf | html
- Evaluate the marginal gain per check in 2020 if household head is employed.
- Solve for the increase in savings that is equivalent to the impact of an additional check on a household's resource available in 2020, given tax and interest rates considerations.
- PrjOptiSNW: snw_a4chk_wrk_bisec_vec()
- Marginal Gain Per Check 2020 Unemployed: mlx | m | pdf | html
- Evaluate the marginal gain per check in 2020 if household head is unemployed.
- Solve for the increase in savings that is equivalent to the impact of an additional check on a household's resource available in 2020, given tax and interest rates considerations.
- PrjOptiSNW: snw_a4chk_unemp_bisec_vec()
- Value in 2020 Given Age, Savings, Shocks, Kids, Educaiton and Marriage: mlx | m | pdf | html
- Expected value and expected consumption from 2020 for a household given at a particular age (18-100), with a particular savings level, at a particular combination of household head and spouse income shocks, with 0 to 4 children, high or low Education status, and married or not married.
- This uses the unemployment probability and generates the average value given the probability of the unemployment state that is dependent on the state-space.
- PrjOptiSNW: snw_evuvw20_jaeemk()
- Expected Value in 2019 Given Age, Savings, Shocks, Kids, Educaiton and Marriage: mlx | m | pdf | html
- Expected value and expected consumption from 2019 for a household at a particular age (18-99), savings level, shocks combinations, kids/education/marriage status, given 2019 optimal savings choices, income shock transition probability as well as household children count transition probabilities.
- PrjOptiSNW: snw_evuvw19_jaeemk()
- Expected Value from 2019 Given Age, Kids, Income and Marriage: mlx | m | pdf | html
- Expected Value from 2019 Given Age, Kids, Income and Marriage.
- Each 2019 income group consists of individuals with varying productivity shocks, savings, and from lower and higher education groups.
- PrjOptiSNW: snw_evuvw19_jmky()
- Expected Value from 2019 Given Age, Kids, Income and Marriage for All Checks: mlx | m | pdf | html
- Expected Value from 2019 Given Age, Kids, Income and Marriage for All Checks.
- This is the gateway function that solves policy functions, derive distributions, computes value in 2020 with and without unemployment shocks with varying check levels, derives 2019 planner expected values given household optimization and shocks, and finds the mass of individuals in different income/age/marital-status bins, and saves the simulated value of check results for the planner.
- PrjOptiSNW: snw_evuvw19_jmky_allchecks()
- Solve for Budget Clearing Tax Rates: mlx | m | pdf | html
- Given welfare checks and unemployment insurance costs, solve for tax rate that clears the budget given household resource availability.
- PrjOptiSNW: snw_find_tax_rate(), snw_tax_hh()
- Calibrate Discount Factor and Normalize GDP: mlx | m | pdf | html
- We calibrate the model so that the Asset/Savings/Capital to GDP/Income ratio is 3.
- We normalize the model so that median household income is equal to 1 in the model.
- PrjOptiSNW: snw_calibrate_beta_norm_gdp()
- Distributional Statistcs by Household Structure and Income Groups: mlx | m | pdf | html
- Summarize overall model distributional and inequality statistics from covid-less times.
- Statistics, including first check MPC, by marital status, children count, and income groups.
- See snwx_evuvw19_jmky_mpc_allocated_m for summarizing function over optimal allocation results.