Utility Function - 2 Occupational Choice

This function evaluates the utility at each combination of current assets, entrepreneurial productivity and future assets a' for a 2 OC model

Back to full code page https://kritikhanna.github.io/BKS-modified/

Function Inputs : asset grid(1 by M) and entrepreneurial productivity grid(1 by N) relevant model parameters required Calls the 2 OC to evaluate COH required to compute utility

Function Outputs : Matrix of utility (both M X N X M) for each combination of a and z and a'

Contents

function [mt_util,mt_coh, mt_k, mt_l, mt_o]=hhsave_util_2OC(varargin)
close all;
bl_profile = false;      % Switch off profile if running a tester/calling from another function
if(bl_profile)
profile off;
profile on;
end

addpath(genpath('/Users/sidhantkhanna/Documents/GitHub/BKS modified/'));

Assigning parameters

if ~isempty(varargin)

    [ar_a,ar_z, ...
        fl_alpha,fl_theta,fl_delta,fl_kappa,fl_r,fl_w,fl_phi,fl_ahi,fl_zhi, ...
         fl_risk,it_zgridno, it_agridno, ...
        ] = varargin{:};

    bl_print  = false;


else
    close all;

    fl_ahi         = 5;
    fl_zhi         = 2.2;
    it_agridno     = 4;
    it_zgridno     = 5;
    ar_a = linspace(0,fl_ahi,it_agridno);
    ar_z = linspace(1,fl_zhi,it_zgridno);
    fl_phi         = 0.5;
    fl_risk        = 2;

    fl_alpha = 0.4;
    fl_theta = 0.79-fl_alpha;
    fl_delta = 0.05;
    fl_kappa = 0;

    [fl_r,fl_w] = ...
        deal(0.05,1.5);
    bl_print       = true;

end

fl_R = fl_r + fl_delta;

Calling OC2

[mt_o, mt_coh, mt_k, mt_l] = OC2(ar_a,ar_z, ...
        fl_alpha,fl_theta,fl_delta,fl_kappa,fl_r,fl_w,fl_phi,fl_ahi,fl_zhi, ...
         it_zgridno, it_agridno);

Computing consumption

mt3_coh= repmat (mt_coh, [1 1 it_agridno]);
%Projecting COH matrix to a third dimension of size of asset grid which will be used for evaluating optimal future assets

mt_futassets=ones(it_agridno,it_zgridno,it_agridno).*ar_a';
% 3d asset matrix to subtract future assets from COH to compute consumption

mt_futassets=permute(mt_futassets,[3 2 1]);
% reorder matrix to correct dimension so as to match COH matrix layout

mt_con =mt3_coh-mt_futassets;                       % Consumption Matrix for each a, z, future a

neg = find(mt_con<=0);                              % Find where consumption is negative ( each combi of a, z, a')

Computing utility

%mt_con(neg) = NaN;

if(fl_risk==1)
    mt_util=log(mt_con);
else
mt_util= (mt_con.^(1-fl_risk) -1)/(1-fl_risk);    % Utility Part of value function
end
mt_util(neg) = -1000;         % Assign big negative value to optimal consumption

Printing outputs

if(bl_print)
    disp('Below is the COH matrix for for all combinations of a, z and future a');
    disp(mt3_coh);
    disp('Below is the future assets matrix for each combination of a, z and future a');
    disp(mt_futassets);
    disp('Below is the consumption matrix for for all combinations of a, z and future a');
    disp(mt_con);
    disp('Below is the utility matrix for for all combinations of a, z and future a');
    disp(mt_util);
 end

if(bl_profile)
profile off;
profile viewer;
st_file_name = '/Users/sidhantkhanna/Documents/GitHub/BKS modified/code/Profile/Households/hhsave_util_2OC';
profsave(profile('info'), st_file_name);
end
Below is the COH matrix for for all combinations of a, z and future a

(:,:,1) =

    1.5000    1.5000    1.5000    1.5000    1.5000
    3.2500    3.2500    3.2500    3.3448    4.0856
    5.0000    5.0000    5.0000    5.6867    6.6982
    6.7500    6.7500    6.8657    7.8679    9.0993


(:,:,2) =

    1.5000    1.5000    1.5000    1.5000    1.5000
    3.2500    3.2500    3.2500    3.3448    4.0856
    5.0000    5.0000    5.0000    5.6867    6.6982
    6.7500    6.7500    6.8657    7.8679    9.0993


(:,:,3) =

    1.5000    1.5000    1.5000    1.5000    1.5000
    3.2500    3.2500    3.2500    3.3448    4.0856
    5.0000    5.0000    5.0000    5.6867    6.6982
    6.7500    6.7500    6.8657    7.8679    9.0993


(:,:,4) =

    1.5000    1.5000    1.5000    1.5000    1.5000
    3.2500    3.2500    3.2500    3.3448    4.0856
    5.0000    5.0000    5.0000    5.6867    6.6982
    6.7500    6.7500    6.8657    7.8679    9.0993

Below is the future assets matrix for each combination of a, z and future a

(:,:,1) =

     0     0     0     0     0
     0     0     0     0     0
     0     0     0     0     0
     0     0     0     0     0


(:,:,2) =

    1.6667    1.6667    1.6667    1.6667    1.6667
    1.6667    1.6667    1.6667    1.6667    1.6667
    1.6667    1.6667    1.6667    1.6667    1.6667
    1.6667    1.6667    1.6667    1.6667    1.6667


(:,:,3) =

    3.3333    3.3333    3.3333    3.3333    3.3333
    3.3333    3.3333    3.3333    3.3333    3.3333
    3.3333    3.3333    3.3333    3.3333    3.3333
    3.3333    3.3333    3.3333    3.3333    3.3333


(:,:,4) =

     5     5     5     5     5
     5     5     5     5     5
     5     5     5     5     5
     5     5     5     5     5

Below is the consumption matrix for for all combinations of a, z and future a

(:,:,1) =

    1.5000    1.5000    1.5000    1.5000    1.5000
    3.2500    3.2500    3.2500    3.3448    4.0856
    5.0000    5.0000    5.0000    5.6867    6.6982
    6.7500    6.7500    6.8657    7.8679    9.0993


(:,:,2) =

   -0.1667   -0.1667   -0.1667   -0.1667   -0.1667
    1.5833    1.5833    1.5833    1.6781    2.4189
    3.3333    3.3333    3.3333    4.0201    5.0315
    5.0833    5.0833    5.1991    6.2012    7.4326


(:,:,3) =

   -1.8333   -1.8333   -1.8333   -1.8333   -1.8333
   -0.0833   -0.0833   -0.0833    0.0115    0.7522
    1.6667    1.6667    1.6667    2.3534    3.3648
    3.4167    3.4167    3.5324    4.5346    5.7659


(:,:,4) =

   -3.5000   -3.5000   -3.5000   -3.5000   -3.5000
   -1.7500   -1.7500   -1.7500   -1.6552   -0.9144
         0         0         0    0.6867    1.6982
    1.7500    1.7500    1.8657    2.8679    4.0993

Below is the utility matrix for for all combinations of a, z and future a

(:,:,1) =

    0.3333    0.3333    0.3333    0.3333    0.3333
    0.6923    0.6923    0.6923    0.7010    0.7552
    0.8000    0.8000    0.8000    0.8242    0.8507
    0.8519    0.8519    0.8543    0.8729    0.8901


(:,:,2) =

   1.0e+03 *

   -1.0000   -1.0000   -1.0000   -1.0000   -1.0000
    0.0004    0.0004    0.0004    0.0004    0.0006
    0.0007    0.0007    0.0007    0.0008    0.0008
    0.0008    0.0008    0.0008    0.0008    0.0009


(:,:,3) =

   1.0e+03 *

   -1.0000   -1.0000   -1.0000   -1.0000   -1.0000
   -1.0000   -1.0000   -1.0000   -0.0863   -0.0003
    0.0004    0.0004    0.0004    0.0006    0.0007
    0.0007    0.0007    0.0007    0.0008    0.0008


(:,:,4) =

   1.0e+03 *

   -1.0000   -1.0000   -1.0000   -1.0000   -1.0000
   -1.0000   -1.0000   -1.0000   -1.0000   -1.0000
   -1.0000   -1.0000   -1.0000   -0.0005    0.0004
    0.0004    0.0004    0.0005    0.0007    0.0008


ans(:,:,1) =

    0.3333    0.3333    0.3333    0.3333    0.3333
    0.6923    0.6923    0.6923    0.7010    0.7552
    0.8000    0.8000    0.8000    0.8242    0.8507
    0.8519    0.8519    0.8543    0.8729    0.8901


ans(:,:,2) =

   1.0e+03 *

   -1.0000   -1.0000   -1.0000   -1.0000   -1.0000
    0.0004    0.0004    0.0004    0.0004    0.0006
    0.0007    0.0007    0.0007    0.0008    0.0008
    0.0008    0.0008    0.0008    0.0008    0.0009


ans(:,:,3) =

   1.0e+03 *

   -1.0000   -1.0000   -1.0000   -1.0000   -1.0000
   -1.0000   -1.0000   -1.0000   -0.0863   -0.0003
    0.0004    0.0004    0.0004    0.0006    0.0007
    0.0007    0.0007    0.0007    0.0008    0.0008


ans(:,:,4) =

   1.0e+03 *

   -1.0000   -1.0000   -1.0000   -1.0000   -1.0000
   -1.0000   -1.0000   -1.0000   -1.0000   -1.0000
   -1.0000   -1.0000   -1.0000   -0.0005    0.0004
    0.0004    0.0004    0.0005    0.0007    0.0008