1 Small Test Exact Solution Spousal Shocks

This is the example vignette for function: snw_vfi_main_bisec_vec from the PrjOptiSNW Package. This function solves for policy function with vectorized bisection. Small Solution Analysis, husband 5 shocks, wife 3 shocks.

1.1 Test SNW_VFI_MAIN Defaults Small

Call the function with default parameters.

mp_param = snw_mp_param('default_small53');
[V_VFI,ap_VFI,cons_VFI,mp_valpol_more] = snw_vfi_main_bisec_vec(mp_param);

SNW_VFI_MAIN_BISEC_VEC: Finished Age Group:18 of 17, time-this-age:0.10593
SNW_VFI_MAIN_BISEC_VEC: Finished Age Group:17 of 17, time-this-age:0.086471
SNW_VFI_MAIN_BISEC_VEC: Finished Age Group:16 of 17, time-this-age:0.079532
SNW_VFI_MAIN_BISEC_VEC: Finished Age Group:15 of 17, time-this-age:0.095977
SNW_VFI_MAIN_BISEC_VEC: Finished Age Group:14 of 17, time-this-age:0.081549
SNW_VFI_MAIN_BISEC_VEC: Finished Age Group:13 of 17, time-this-age:0.08703
SNW_VFI_MAIN_BISEC_VEC: Finished Age Group:12 of 17, time-this-age:0.089059
SNW_VFI_MAIN_BISEC_VEC: Finished Age Group:11 of 17, time-this-age:0.094402
SNW_VFI_MAIN_BISEC_VEC: Finished Age Group:10 of 17, time-this-age:0.10011
SNW_VFI_MAIN_BISEC_VEC: Finished Age Group:9 of 17, time-this-age:0.093424
SNW_VFI_MAIN_BISEC_VEC: Finished Age Group:8 of 17, time-this-age:0.095447
SNW_VFI_MAIN_BISEC_VEC: Finished Age Group:7 of 17, time-this-age:0.10832
SNW_VFI_MAIN_BISEC_VEC: Finished Age Group:6 of 17, time-this-age:0.089896
SNW_VFI_MAIN_BISEC_VEC: Finished Age Group:5 of 17, time-this-age:0.09249
SNW_VFI_MAIN_BISEC_VEC: Finished Age Group:4 of 17, time-this-age:0.094699
SNW_VFI_MAIN_BISEC_VEC: Finished Age Group:3 of 17, time-this-age:0.087703
SNW_VFI_MAIN_BISEC_VEC: Finished Age Group:2 of 17, time-this-age:0.0939
SNW_VFI_MAIN_BISEC_VEC: Finished Age Group:1 of 17, time-this-age:0.087152
Completed SNW_VFI_MAIN_BISEC_VEC;SNW_MP_PARAM=default_small53;SNW_MP_CONTROL=default_base;time=1.7157

1.2 Small Param Results Define Frames

Define the matrix dimensions names and dimension vector values. Policy and Value Functions share the same ND dimensional structure.

% Grids:
age_grid = [19, 22:5:97, 100];
agrid = mp_param('agrid')';
eta_H_grid = mp_param('eta_H_grid')';
eta_S_grid = mp_param('eta_S_grid')';
ar_st_eta_HS_grid = string(cellstr([num2str(eta_H_grid', 'hz=%3.2f;'), num2str(eta_S_grid', 'wz=%3.2f')]));
edu_grid = [0,1];
marry_grid = [0,1];
kids_grid = (1:1:mp_param('n_kidsgrid'))';
% NaN(n_jgrid,n_agrid,n_etagrid,n_educgrid,n_marriedgrid,n_kidsgrid);
cl_mp_datasetdesc = {};
cl_mp_datasetdesc{1} = containers.Map({'name', 'labval'}, {'age', age_grid});
cl_mp_datasetdesc{2} = containers.Map({'name', 'labval'}, {'savings', agrid});
cl_mp_datasetdesc{3} = containers.Map({'name', 'labval'}, {'eta', 1:length(eta_H_grid)});
cl_mp_datasetdesc{4} = containers.Map({'name', 'labval'}, {'edu', edu_grid});
cl_mp_datasetdesc{5} = containers.Map({'name', 'labval'}, {'marry', marry_grid});
cl_mp_datasetdesc{6} = containers.Map({'name', 'labval'}, {'kids', kids_grid});

1.3 Analyze Savings and Shocks

First, analyze Savings Levels and Shocks, Aggregate Over All Others, and do various other calculations.

% Generate some Data
mp_support_graph = containers.Map('KeyType', 'char', 'ValueType', 'any');
mp_support_graph('cl_st_xtitle') = {'Savings States, a'};
mp_support_graph('st_legend_loc') = 'best';
mp_support_graph('bl_graph_logy') = true; % do not log
mp_support_graph('it_legend_select') = 9; % how many shock legends to show
mp_support_graph('cl_colors') = 'jet';

MEAN(VAL(A,Z)), MEAN(AP(A,Z)), MEAN(C(A,Z))

Tabulate value and policies along savings and shocks:

% Set
% NaN(n_jgrid,n_agrid,n_etagrid,n_educgrid,n_marriedgrid,n_kidsgrid);
ar_permute = [1,4,5,6,3,2];
% Value Function
tb_az_v = ff_summ_nd_array("MEAN(VAL(A,Z))", V_VFI, true, ["mean"], 4, 1, cl_mp_datasetdesc, ar_permute);

xxx  MEAN(VAL(A,Z))  xxxxxxxxxxxxxxxxxxxxxxxxxxx
    group     savings     mean_eta_1    mean_eta_2    mean_eta_3    mean_eta_4    mean_eta_5    mean_eta_6    mean_eta_7    mean_eta_8    mean_eta_9    mean_eta_10    mean_eta_11    mean_eta_12    mean_eta_13    mean_eta_14    mean_eta_15
    _____    _________    __________    __________    __________    __________    __________    __________    __________    __________    __________    ___________    ___________    ___________    ___________    ___________    ___________

      1              0      -24.423       -14.383       -9.0838       -6.1681       -4.6368        -21.16       -12.873       -8.1373       -5.3766       -3.8904        -16.593        -9.8032        -6.1944        -4.1246         -2.992  
      2      0.0097656      -23.655       -14.141       -8.9428       -6.0477        -4.521       -20.721       -12.725       -8.0508       -5.3059       -3.8237        -16.217        -9.6854        -6.1244        -4.0657        -2.9359  
      3       0.078125      -20.274       -12.864       -8.2087        -5.441       -3.9447       -18.597       -11.897       -7.5808       -4.9362       -3.4813        -14.463        -9.0428        -5.7563        -3.7684        -2.6574  
      4        0.26367      -16.052       -10.951       -7.1333        -4.627       -3.2033       -15.258       -10.427       -6.7883       -4.3683       -2.9802        -11.797        -7.9418        -5.1698        -3.3421        -2.2775  
      5          0.625      -12.169       -8.9647       -6.0525        -3.918       -2.6128       -11.753         -8.67       -5.8499       -3.7794       -2.5033        -9.0813        -6.6522        -4.4995        -2.9252        -1.9394  
      6         1.2207      -8.9956       -7.1143       -5.0287       -3.3224         -2.17       -8.7621        -6.936       -4.9021        -3.241       -2.1112        -6.8238        -5.3898        -3.8277         -2.555         -1.673  
      7         2.1094      -6.6026       -5.5315        -4.126       -2.8111       -1.8354       -6.4689       -5.4217       -4.0462       -2.7603       -1.8014        -5.1255        -4.2907        -3.2213        -2.2246         -1.465  
      8         3.3496      -4.8705       -4.2629       -3.3542       -2.3677       -1.5738       -4.7931       -4.1953       -3.3029       -2.3333       -1.5524        -3.8915        -3.3981         -2.689         -1.925        -1.2946  
      9              5      -3.6341       -3.2853       -2.7087       -1.9911       -1.3595       -3.5888       -3.2436       -2.6752       -1.9675       -1.3452        -2.9917        -2.6943        -2.2294        -1.6593        -1.1473  
     10         7.1191      -2.7516       -2.5471       -2.1826       -1.6748       -1.1772       -2.7246       -2.5212       -2.1608       -1.6587       -1.1674        -2.3319        -2.1467         -1.842        -1.4274        -1.0161  
     11         9.7656      -2.1163       -1.9932       -1.7614       -1.4073       -1.0193       -2.0999        -1.977       -1.7471       -1.3963       -1.0123        -1.8424        -1.7234        -1.5212        -1.2238       -0.89713  
     12         12.998       -1.653       -1.5768       -1.4275       -1.1818      -0.88344       -1.6428       -1.5665        -1.418       -1.1741       -0.8782        -1.4731        -1.3952        -1.2592        -1.0464       -0.79051  
     13         16.875      -1.3103       -1.2619       -1.1642      -0.99332      -0.76691       -1.3038       -1.2552       -1.1578      -0.98793      -0.76296        -1.1903        -1.1387        -1.0462       -0.89385       -0.69565  
     14         21.455      -1.0532       -1.0216      -0.95651      -0.83698      -0.66655       -1.0489       -1.0172      -0.95213      -0.83317      -0.66362       -0.97149       -0.93682       -0.87335       -0.76404       -0.61178  
     15         26.797     -0.85714      -0.83614      -0.79193       -0.7076      -0.57964      -0.85429      -0.83312      -0.78891      -0.70488      -0.57747       -0.80054       -0.77679       -0.73269       -0.65391       -0.53753  
     16         32.959      -0.7057      -0.69138      -0.66083      -0.60072      -0.50456      -0.70375       -0.6893      -0.65871      -0.59875      -0.50294       -0.66579        -0.6492       -0.61808       -0.56093       -0.47215  
     17             40     -0.58719      -0.57722      -0.55573      -0.51237      -0.43988      -0.58583      -0.57576      -0.55422      -0.51094      -0.43866       -0.55862       -0.54682       -0.52452       -0.48265       -0.41486  
     18         47.979     -0.49334      -0.48626      -0.47088      -0.43924      -0.38431      -0.49239      -0.48522      -0.46979      -0.43817      -0.38338       -0.47262       -0.46407       -0.44785       -0.41687       -0.36491  
     19         56.953     -0.41818      -0.41306      -0.40187      -0.37849      -0.33661      -0.41749       -0.4123      -0.40107      -0.37769      -0.33589       -0.40296       -0.39666       -0.38469       -0.36151       -0.32149  
     20         66.982     -0.35736      -0.35359      -0.34532      -0.32783      -0.29568      -0.35685      -0.35303      -0.34473      -0.32724      -0.29513       -0.34603       -0.34132       -0.33236       -0.31483       -0.28383  
     21         78.125     -0.30764      -0.30483      -0.29864      -0.28541      -0.26055      -0.30727      -0.30442       -0.2982      -0.28496      -0.26012       -0.29912       -0.29556       -0.28878       -0.27538        -0.2512  
     22         90.439     -0.26663      -0.26451      -0.25982      -0.24971      -0.23034      -0.26635       -0.2642      -0.25949      -0.24936         -0.23       -0.26018       -0.25746       -0.25226       -0.24193       -0.22294  
     23         103.98     -0.23253      -0.23091      -0.22732      -0.21951      -0.20431      -0.23232      -0.23068      -0.22707      -0.21925      -0.20405       -0.22759       -0.22549       -0.22148       -0.21344       -0.19844  
     24         118.82     -0.20396      -0.20271      -0.19994      -0.19386      -0.18184       -0.2038      -0.20253      -0.19974      -0.19365      -0.18164       -0.20014       -0.19851       -0.19538       -0.18908       -0.17714  
     25            135     -0.17985      -0.17888      -0.17671      -0.17193      -0.16238      -0.17973      -0.17874      -0.17656      -0.17177      -0.16221       -0.17685       -0.17557        -0.1731        -0.1681       -0.15852  

% Aprime Choice
tb_az_ap = ff_summ_nd_array("MEAN(AP(A,Z))", ap_VFI, true, ["mean"], 4, 1, cl_mp_datasetdesc, ar_permute);

xxx  MEAN(AP(A,Z))  xxxxxxxxxxxxxxxxxxxxxxxxxxx
    group     savings     mean_eta_1    mean_eta_2    mean_eta_3    mean_eta_4    mean_eta_5    mean_eta_6    mean_eta_7    mean_eta_8    mean_eta_9    mean_eta_10    mean_eta_11    mean_eta_12    mean_eta_13    mean_eta_14    mean_eta_15
    _____    _________    __________    __________    __________    __________    __________    __________    __________    __________    __________    ___________    ___________    ___________    ___________    ___________    ___________

      1              0    3.2159e-05    0.0024668      0.032046      0.17185       0.75713      0.0035503     0.0057037      0.047179      0.22128        0.83929        1.5949         1.7717         1.9927         2.3825          3.261   
      2      0.0097656    0.00055365    0.0039513      0.034103      0.17524       0.76251      0.0051645     0.0082793      0.050114      0.22508        0.84479        1.5992         1.7765         1.9982         2.3881         3.2676   
      3       0.078125      0.015815     0.020023      0.052271      0.20181        0.8015       0.036634      0.037379      0.078236       0.2558        0.88531        1.6417         1.8168         2.0406         2.4302         3.3143   
      4        0.26367      0.094638     0.094808       0.12856      0.29193       0.91314        0.14372       0.15181       0.19153      0.36171         1.0035        1.7785         1.9511         2.1757          2.555         3.4442   
      5          0.625       0.31851      0.32442       0.35753      0.52484        1.1543        0.39249       0.40496       0.43751      0.61133         1.2467        2.0525         2.2281         2.4483         2.8196         3.7031   
      6         1.2207       0.75143      0.75176       0.79303      0.95962        1.5772         0.8339       0.84934       0.88966       1.0532         1.6786        2.5043         2.6788         2.9087         3.2694         4.1441   
      7         2.1094        1.4241       1.4284        1.4709       1.6269        2.2293         1.5113        1.5285        1.5802       1.7093          2.329        3.1791         3.3637         3.5917         3.9381         4.7981   
      8         3.3496        2.3733       2.3796         2.421       2.5737        3.1535         2.4564        2.4749        2.5266        2.646         3.2655         4.145         4.3264         4.5493         4.8846         5.7519   
      9              5        3.6394       3.6466        3.6884       3.8506        4.3901         3.7225        3.7419        3.7947       3.9465         4.5072        5.4003         5.5927          5.824         6.1639         6.9962   
     10         7.1191        5.2875       5.2955        5.3372       5.5015        5.9876         5.3719        5.3915        5.4459       5.6201          6.097        7.0272         7.2068         7.4331         7.8074         8.5649   
     11         9.7656        7.3153       7.3234        7.3642       7.5288        8.0042         7.4069        7.4251        7.4813       7.6575         8.0966        9.1171         9.2822         9.5067         9.8589         10.592   
     12         12.998        9.7556       9.7616        9.8006        9.967         10.49         9.8338        9.8499        9.9027       10.084         10.556        11.529          11.72          11.94         12.294         13.012   
     13         16.875        12.766       12.773        12.807        12.97        13.562         12.844        12.858        12.906       13.086         13.646        14.521          14.72          14.97         15.326         16.074   
     14         21.455        16.338       16.342        16.377       16.524        17.139         16.426         16.44        16.486       16.653         17.268        18.053         18.254         18.515         18.904         19.658   
     15         26.797        20.401       20.403        20.431        20.57        21.185         20.487        20.497        20.537       20.693         21.324        22.072         22.259         22.513          22.91         23.737   
     16         32.959        25.088       25.095        25.124       25.248        25.842         25.176        25.189        25.224       25.366         25.983        26.768         26.951          27.19         27.575         28.418   
     17             40        30.463       30.471         30.51       30.633        31.193          30.54        30.556        30.606       30.737         31.322        32.154         32.337         32.575         32.941         33.784   
     18         47.979        36.558       36.567        36.609       36.754        37.274         36.633        36.649        36.697       36.853         37.394        38.337          38.51         38.745         39.114         39.912   
     19         56.953         43.57       43.576        43.612       43.757        44.279         43.643        43.658        43.705        43.86         44.396          45.2         45.358         45.578          45.94         46.719   
     20         66.982        51.378       51.387        51.429       51.567        52.101         51.457        51.473        51.523       51.675          52.22        52.915         53.068         53.277          53.62         54.386   
     21         78.125        59.666       59.675        59.721       59.878         60.41          59.76        59.777        59.832       59.994         60.541        61.518         61.668         61.872         62.207         62.952   
     22         90.439         69.02       69.027        69.069       69.228        69.775           69.1        69.116        69.169       69.339         69.894        70.927         71.078         71.279         71.606         72.331   
     23         103.98        79.509       79.516        79.557       79.706         80.27         79.589        79.604        79.653       79.814         80.386        81.356         81.509         81.709         82.032         82.742   
     24         118.82         90.88       90.887        90.929       91.074        91.625         90.956        90.971        91.022        91.18         91.743        92.752         92.917         93.126         93.447         94.141   
     25            135        103.23       103.23        103.27       103.42        103.97         103.31        103.32        103.37       103.53         104.08        105.13         105.34          105.6            106         106.84   

% Consumption Choices
tb_az_c = ff_summ_nd_array("MEAN(C(A,Z))", cons_VFI, true, ["mean"], 4, 1, cl_mp_datasetdesc, ar_permute);

xxx  MEAN(C(A,Z))  xxxxxxxxxxxxxxxxxxxxxxxxxxx
    group     savings     mean_eta_1    mean_eta_2    mean_eta_3    mean_eta_4    mean_eta_5    mean_eta_6    mean_eta_7    mean_eta_8    mean_eta_9    mean_eta_10    mean_eta_11    mean_eta_12    mean_eta_13    mean_eta_14    mean_eta_15
    _____    _________    __________    __________    __________    __________    __________    __________    __________    __________    __________    ___________    ___________    ___________    ___________    ___________    ___________

      1              0     0.16881       0.29125       0.55695        1.1299        2.3014       0.29922       0.42884       0.69049        1.2391        2.3904         1.4929         1.6544         1.9693         2.5658         3.7569   
      2      0.0097656     0.17988       0.30127       0.56634        1.1379        2.3074       0.30913       0.43773       0.69898        1.2467        2.3963         1.5001          1.661         1.9751         2.5716         3.7617   
      3       0.078125     0.24566       0.36575       0.62833        1.1912        2.3483       0.35831       0.48892       0.75085        1.2958        2.4355         1.5378         1.7008         2.0126         2.6092         3.7946   
      4        0.26367     0.38648       0.50942       0.76949         1.318        2.4533        0.4699        0.5923       0.85458        1.4064        2.5337         1.6186         1.7834         2.0939         2.7005         3.8807   
      5          0.625     0.58919       0.70456       0.96359        1.5071        2.6337       0.64619       0.76283         1.031        1.5783        2.7116         1.7678         1.9286         2.2426         2.8567         4.0424   
      6         1.2207     0.85722       0.97603        1.2247        1.7675        2.9054        0.9039        1.0159        1.2745        1.8309        2.9736         2.0124         2.1733         2.4764         3.1003         4.2945   
      7         2.1094      1.2268        1.3395        1.5846        2.1362        3.2884        1.2668        1.3754        1.6207          2.21        3.3577         2.3746         2.5243         2.8282         3.4654         4.6739   
      8         3.3496      1.7279         1.837        2.0808        2.6338        3.8076        1.7706        1.8764        2.1198        2.7171         3.864          2.854         3.0061         3.3138         3.9611         5.1618   
      9              5      2.3875        2.4944        2.7359        3.2775        4.4904        2.4289        2.5327        2.7733        3.3366        4.5412         3.5199         3.6601         3.9585         4.6003         5.8351   
     10         7.1191      3.2081        3.3133        3.5534        4.0911        5.3563        3.2473          3.35        3.5876         4.127        5.4144         4.3576         4.5101         4.8127         5.4191         6.7283   
     11         9.7656      4.2601        4.3643        4.6042        5.1402        6.4149        4.2913        4.3947        4.6296        5.1656        6.4897          5.344         5.5106         5.8143         6.4421         7.7753   
     12         12.998      5.5783        5.6843        5.9251        6.4581         7.684        5.6225        5.7276         5.965        6.4951        7.7847         6.6877         6.8281         7.1356         7.7609         9.1086   
     13         16.875      7.0733        7.1787        7.4234        7.9594        9.1154        7.1181        7.2243        7.4664        7.9965        9.1977         8.1993         8.3316         8.6084         9.2321         10.549   
     14         21.455       8.823        8.9302        9.1737        9.7243        10.857        8.8568        8.9633         9.206        9.7494        10.894         9.9861         10.116         10.382         10.972         12.283   
     15         26.797      10.964        11.073        11.324        11.882        13.013        10.999        11.111        11.359        11.912        13.041          12.17         12.314         12.587         13.168         14.405   
     16         32.959      13.433        13.538        13.787         14.36        15.511        13.467        13.574        13.828        14.395        15.537         14.629         14.778         15.065         15.658         16.878   
     17             40      16.233        16.337        16.576        17.149        18.335        16.278        16.383        16.621        17.198        18.372         17.418         17.566         17.854         18.466         19.687   
     18         47.979      19.402        19.505        19.741        20.291        21.516        19.449        19.553        19.793        20.346        21.562         20.498         20.656         20.947         21.555          22.82   
     19         56.953       22.81        22.914        23.156        23.707         24.93        22.858        22.963        23.205        23.757        24.979         24.053         24.227         24.532         25.148         26.431   
     20         66.982      26.645        26.747        26.982         27.54         28.75        26.687        26.791         27.03        27.585        28.798         27.981          28.16         28.477         29.111         30.407   
     21         78.125      31.292        31.394        31.626        32.165        33.377        31.319        31.422        31.656        32.201        33.412         32.313         32.494         32.816         33.459         34.776   
     22         90.439      36.234        36.338        36.573         37.11        38.307        36.274        36.379        36.614        37.152        38.354         37.199          37.38         37.704         38.354         39.691   
     23         103.98      41.468        41.572        41.808        42.355        43.535        41.509        41.615        41.854          42.4        43.585         42.494         42.672         42.998         43.651         45.004   
     24         118.82      47.317        47.421        47.656        48.207          49.4        47.362        47.467        47.704        48.254        49.447         48.317         48.483           48.8         49.456         50.824   
     25            135      53.752        53.857        54.095        54.642        55.842        53.796        53.902        54.143        54.689        55.891         54.721         54.845         55.109         55.682         56.909   

Graph Mean Values:

mp_support_graph('cl_st_graph_title') = {'MEAN(value(a,z)), a=x, z=color'};
mp_support_graph('cl_st_ytitle') = {'MEAN(value(a,z))'};
ff_graph_grid((tb_az_v{1:end, 3:end})', ar_st_eta_HS_grid, agrid, mp_support_graph);

Graph Mean Savings Choices:

mp_support_graph('cl_st_graph_title') = {'MEAN(APRIME(a,z)), a=x, z=color'};
mp_support_graph('cl_st_ytitle') = {'MEAN(APRIME(a,z))'};
ff_graph_grid((tb_az_ap{1:end, 3:end})', ar_st_eta_HS_grid, agrid, mp_support_graph);

Graph Mean Consumption:

mp_support_graph('cl_st_graph_title') = {'MEAN(C(a,z)), a=x, z=color'};
mp_support_graph('cl_st_ytitle') = {'MEAN(C(a,z))'};
ff_graph_grid((tb_az_c{1:end, 3:end})', ar_st_eta_HS_grid, agrid, mp_support_graph);

1.4 Analyze Kids and Marriage and Age

Aggregating over education, savings, and shocks, what are the differential effects of Marriage and Age.

% Generate some Data
mp_support_graph = containers.Map('KeyType', 'char', 'ValueType', 'any');
ar_row_grid = ["k0M0", "K1M0", "K2M0", "k0M1", "K1M1", "K2M1"];
mp_support_graph('cl_st_xtitle') = {'Age'};
mp_support_graph('st_legend_loc') = 'best';
mp_support_graph('bl_graph_logy') = true; % do not log
mp_support_graph('st_rounding') = '6.2f'; % format shock legend
mp_support_graph('cl_scatter_shapes') = { 'o', 'd' ,'s', 'o', 'd', 's'};
mp_support_graph('cl_colors') = {'red', 'red', 'red', 'blue', 'blue', 'blue'};

MEAN(VAL(KM,J)), MEAN(AP(KM,J)), MEAN(C(KM,J))

Tabulate value and policies:

% Set
% NaN(n_jgrid,n_agrid,n_etagrid,n_educgrid,n_marriedgrid,n_kidsgrid);
ar_permute = [2,3,4,1,6,5];
% Value Function
tb_az_v = ff_summ_nd_array("MEAN(VAL(KM,J))", V_VFI, true, ["mean"], 3, 1, cl_mp_datasetdesc, ar_permute);

xxx  MEAN(VAL(KM,J))  xxxxxxxxxxxxxxxxxxxxxxxxxxx
    group    kids    marry    mean_age_19    mean_age_22    mean_age_27    mean_age_32    mean_age_37    mean_age_42    mean_age_47    mean_age_52    mean_age_57    mean_age_62    mean_age_67    mean_age_72    mean_age_77    mean_age_82    mean_age_87    mean_age_92    mean_age_97    mean_age_100
    _____    ____    _____    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ____________

      1       1        0        -4.7384        -4.2839        -3.9125        -3.6403        -3.4202        -3.2286        -3.0466        -2.8601        -2.6595        -2.4491        -2.2399        -2.0731        -2.3629        -1.8637        -1.4355         -1.116       -0.89281        -0.68658  
      2       2        0        -6.2307        -5.5732         -5.014        -4.5943        -4.2483        -3.9542        -3.6887         -3.434        -3.1782        -2.9257        -2.6801        -2.4926        -2.8794        -2.3137        -1.8328        -1.4683        -1.2096        -0.97097  
      3       3        0        -6.9818        -6.3368        -5.7685        -5.3334        -4.9708        -4.6532        -4.3595        -4.0736        -3.7846        -3.4985        -3.2208        -3.0125        -3.5228        -2.8558        -2.2747        -1.8248        -1.5002         -1.1892  
      4       1        1        -3.4759        -3.1424        -2.8538        -2.6272        -2.4359        -2.2663        -2.1075        -1.9513        -1.7931        -1.6374        -1.4932        -1.3847        -1.4858        -1.1944       -0.94216       -0.75023       -0.61798        -0.49489  
      5       2        1         -4.325        -3.9032        -3.5196        -3.2101        -2.9428        -2.7083        -2.4943        -2.2914        -2.0936        -1.9053        -1.7315        -1.5985        -1.6948        -1.3759        -1.0987       -0.88795       -0.74204        -0.60546  
      6       3        1        -4.7282        -4.3225        -3.9432        -3.6317        -3.3597        -3.1133        -2.8816        -2.6564        -2.4324        -2.2154        -2.0111        -1.8459        -1.9256        -1.5703        -1.2589        -1.0197       -0.85265        -0.69356  

% Aprime Choice
tb_az_ap = ff_summ_nd_array("MEAN(AP(KM,J))", ap_VFI, true, ["mean"], 3, 1, cl_mp_datasetdesc, ar_permute);

xxx  MEAN(AP(KM,J))  xxxxxxxxxxxxxxxxxxxxxxxxxxx
    group    kids    marry    mean_age_19    mean_age_22    mean_age_27    mean_age_32    mean_age_37    mean_age_42    mean_age_47    mean_age_52    mean_age_57    mean_age_62    mean_age_67    mean_age_72    mean_age_77    mean_age_82    mean_age_87    mean_age_92    mean_age_97    mean_age_100
    _____    ____    _____    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ____________

      1       1        0        34.931         34.726         34.665         34.554         34.362         34.077         33.682         33.147         32.422           31.5         30.819         29.713         26.817         24.458         21.039         16.761         11.058            0      
      2       2        0        34.603         34.334         34.198         33.995         33.692         33.286         32.762         32.089         31.289         30.736         29.885         28.361         25.892         23.172         19.841         15.524         10.196            0      
      3       3        0        34.187         33.968         33.877         33.705         33.427         33.033          32.51          31.83          31.11          30.61         29.726         28.203         25.828         23.157         19.895         15.696          10.38            0      
      4       1        1        35.713         35.611           35.7         35.727          35.66         35.493         35.215         34.799         34.189         33.405         32.672         31.512         27.898         25.399          21.82         17.365         11.474            0      
      5       2        1        35.368         35.246         35.284         35.242         35.101         34.849         34.477         33.956         33.237         32.553         31.755         30.453         27.335         24.621         21.078         16.723         10.908            0      
      6       3        1        34.903          34.81          34.86         34.834           34.7         34.447         34.074         33.542         32.826         32.188         31.388         30.042         27.293         24.589         21.089         16.779         11.002            0      

% Consumption Choices
tb_az_c = ff_summ_nd_array("MEAN(C(KM,J))", cons_VFI, true, ["mean"], 3, 1, cl_mp_datasetdesc, ar_permute);

xxx  MEAN(C(KM,J))  xxxxxxxxxxxxxxxxxxxxxxxxxxx
    group    kids    marry    mean_age_19    mean_age_22    mean_age_27    mean_age_32    mean_age_37    mean_age_42    mean_age_47    mean_age_52    mean_age_57    mean_age_62    mean_age_67    mean_age_72    mean_age_77    mean_age_82    mean_age_87    mean_age_92    mean_age_97    mean_age_100
    _____    ____    _____    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ____________

      1       1        0        6.8531         7.1729         7.4988         7.8167         8.1435         8.4993         8.9181         9.4437         10.134         10.995         11.582         12.551          14.27         16.629         20.048         24.326         30.029          41.087   
      2       2        0         7.182         7.5653         7.9659         8.3756          8.813         9.2907         9.8382         10.502         11.267         11.759         12.516         13.903         15.195         17.915         21.247         25.563         30.891          41.087   
      3       3        0        7.5973          7.931         8.2872         8.6657         9.0783         9.5438         10.091         10.761         11.445         11.885         12.675         14.061         15.259          17.93         21.192         25.392         30.707          41.087   
      4       1        1        7.7992          8.182         8.5624         8.9321          9.311         9.7148         10.172         10.725         11.436         12.283         13.029         14.136         15.519         18.092          21.74         26.258         32.205          43.729   
      5       2        1         7.879         8.2553         8.6555         9.0645         9.4908         9.9535         10.481         11.116         11.915         12.643         13.437         14.674         16.094         18.883         22.494         26.913         32.784          43.743   
      6       3        1        8.1608         8.4911         8.8566         9.2297         9.6299         10.077         10.589         11.219             12         12.669         13.454         14.725         16.228          19.01         22.581         26.956         32.792          43.847   

Graph Mean Values:

mp_support_graph('cl_st_graph_title') = {'MEAN(value(KM,J)), a=age, z=kids+marry'};
mp_support_graph('cl_st_ytitle') = {'MEAN(value(KM,J))'};
ff_graph_grid((tb_az_v{1:end, 4:end}), ar_row_grid, age_grid, mp_support_graph);

Graph Mean Savings Choices:

mp_support_graph('cl_st_graph_title') = {'MEAN(APRIME(KM,J)), a=x, z=color'};
mp_support_graph('cl_st_ytitle') = {'MEAN(APRIME(KM,J))'};
ff_graph_grid((tb_az_ap{1:end, 4:end}), ar_row_grid, age_grid, mp_support_graph);

Graph Mean Consumption:

mp_support_graph('cl_st_graph_title') = {'MEAN(C(KM,J)), a=x, z=color'};
mp_support_graph('cl_st_ytitle') = {'MEAN(C(KM,J))'};
ff_graph_grid((tb_az_c{1:end, 4:end}), ar_row_grid, age_grid, mp_support_graph);

1.5 Analyze Education and Marriage and Age

Aggregating over education, savings, and shocks, what are the differential effects of Marriage and Age.

% Generate some Data
mp_support_graph = containers.Map('KeyType', 'char', 'ValueType', 'any');
ar_row_grid = ["E0M0", "E1M0", "E0M1", "E1M1"];
mp_support_graph('cl_st_xtitle') = {'Age'};
mp_support_graph('st_legend_loc') = 'best';
mp_support_graph('bl_graph_logy') = true; % do not log
mp_support_graph('st_rounding') = '6.2f'; % format shock legend
mp_support_graph('cl_scatter_shapes') = {'*', 'p', '*','p' };
mp_support_graph('cl_colors') = {'red', 'red', 'blue', 'blue'};

MEAN(VAL(EKM,J)), MEAN(AP(EKM,J)), MEAN(C(EKM,J))

Tabulate value and policies:

% Set
% NaN(n_jgrid,n_agrid,n_etagrid,n_educgrid,n_marriedgrid,n_kidsgrid);
ar_permute = [2,3,6,1,4,5];
% Value Function
tb_az_v = ff_summ_nd_array("MEAN(VAL(EKM,J))", V_VFI, true, ["mean"], 3, 1, cl_mp_datasetdesc, ar_permute);

xxx  MEAN(VAL(EKM,J))  xxxxxxxxxxxxxxxxxxxxxxxxxxx
    group    edu    marry    mean_age_19    mean_age_22    mean_age_27    mean_age_32    mean_age_37    mean_age_42    mean_age_47    mean_age_52    mean_age_57    mean_age_62    mean_age_67    mean_age_72    mean_age_77    mean_age_82    mean_age_87    mean_age_92    mean_age_97    mean_age_100
    _____    ___    _____    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ____________

      1       0       0        -6.4015        -5.8666        -5.3879        -4.9966        -4.6557        -4.3525        -4.0711        -3.7972        -3.5191        -3.2399        -2.9631        -2.7398        -3.0999        -2.4877        -1.9609         -1.561        -1.2765         -1.0093  
      2       1       0        -5.5658        -4.9294        -4.4088        -4.0487        -3.7705        -3.5382        -3.3254        -3.1146        -2.8958        -2.6757        -2.4641        -2.3123        -2.7435         -2.201        -1.7345        -1.3784        -1.1253        -0.88856  
      3       0       1        -4.4764        -4.1029        -3.7581        -3.4622        -3.1968        -2.9557        -2.7306        -2.5141        -2.3006        -2.0946        -1.9015        -1.7476         -1.819         -1.475        -1.1758       -0.94656       -0.78798        -0.63847  
      4       1       1        -3.8764        -3.4759        -3.1196        -2.8504        -2.6288        -2.4363        -2.2583        -2.0853        -1.9122        -1.7442        -1.5889        -1.4719        -1.5851        -1.2854         -1.024       -0.82536       -0.68713        -0.55747  

% Aprime Choice
tb_az_ap = ff_summ_nd_array("MEAN(AP(EKM,J))", ap_VFI, true, ["mean"], 3, 1, cl_mp_datasetdesc, ar_permute);

xxx  MEAN(AP(EKM,J))  xxxxxxxxxxxxxxxxxxxxxxxxxxx
    group    edu    marry    mean_age_19    mean_age_22    mean_age_27    mean_age_32    mean_age_37    mean_age_42    mean_age_47    mean_age_52    mean_age_57    mean_age_62    mean_age_67    mean_age_72    mean_age_77    mean_age_82    mean_age_87    mean_age_92    mean_age_97    mean_age_100
    _____    ___    _____    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ____________

      1       0       0        34.682         34.444         34.272         34.048         33.753         33.374         32.888         32.256         31.512         30.851          30.02         28.595          26.17         23.589         20.254         15.987         10.542            0      
      2       1       0        34.465         34.241         34.222         34.121         33.901         33.556         33.081         32.455         31.703         31.046         30.267         28.923         26.188         23.603         20.262             16         10.548            0      
      3       0       1        35.363         35.234         35.193         35.099         34.934         34.686         34.331         33.831         33.132         32.407         31.616         30.323         27.362         24.751         21.229         16.874         11.069            0      
      4       1       1        35.293          35.21          35.37         35.437         35.374         35.174         34.846         34.367         33.703         33.023         32.261         31.015         27.656         24.989         21.429         17.037         11.188            0      

% Consumption Choices
tb_az_c = ff_summ_nd_array("MEAN(C(EKM,J))", cons_VFI, true, ["mean"], 3, 1, cl_mp_datasetdesc, ar_permute);

xxx  MEAN(C(EKM,J))  xxxxxxxxxxxxxxxxxxxxxxxxxxx
    group    edu    marry    mean_age_19    mean_age_22    mean_age_27    mean_age_32    mean_age_37    mean_age_42    mean_age_47    mean_age_52    mean_age_57    mean_age_62    mean_age_67    mean_age_72    mean_age_77    mean_age_82    mean_age_87    mean_age_92    mean_age_97    mean_age_100
    _____    ___    _____    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ___________    ____________

      1       0       0        7.1022         7.4087         7.7357         8.0845         8.4713         8.9105          9.427         10.062         10.782         11.389         12.136         13.445           14.9          17.48         20.815         25.082         30.528           41.07   
      2       1       0        7.3195         7.7041         8.0988         8.4875         8.8852          9.312         9.8044         10.409         11.116         11.703         12.379         13.565         14.917         17.502         20.843         25.105         30.557          41.105   
      3       0       1        7.7587         8.0743         8.4083         8.7618         9.1489         9.5822         10.086         10.701          11.48         12.245         13.031          14.27         15.805         18.483         22.066         26.477         32.333          43.447   
      4       1       1         8.134         8.5446         8.9747         9.3891         9.8055         10.248         10.742         11.338         12.087         12.819         13.583         14.752         16.089          18.84         22.478         26.941         32.854          44.099   

Graph Mean Values:

mp_support_graph('cl_st_graph_title') = {'MEAN(value(EM,J)), a=age, z=kids+marry'};
mp_support_graph('cl_st_ytitle') = {'MEAN(value(EM,J))'};
ff_graph_grid((tb_az_v{1:end, 4:end}), ar_row_grid, age_grid, mp_support_graph);

Graph Mean Savings Choices:

mp_support_graph('cl_st_graph_title') = {'MEAN(APRIME(EK,J)), a=x, z=color'};
mp_support_graph('cl_st_ytitle') = {'MEAN(APRIME(EK,J))'};
ff_graph_grid((tb_az_ap{1:end, 4:end}), ar_row_grid, age_grid, mp_support_graph);

Graph Mean Consumption:

mp_support_graph('cl_st_graph_title') = {'MEAN(C(EK,J)), a=x, z=color'};
mp_support_graph('cl_st_ytitle') = {'MEAN(C(EK,J))'};
ff_graph_grid((tb_az_c{1:end, 4:end}), ar_row_grid, age_grid, mp_support_graph);