Utility Function - 3 Occupational Choice

This function evaluates the utility at each combination of current assets, entrepreneurial productivity, labor opportunity and future assets a' for a 3 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), labor opportunity grid (1 by 2) relevant model parameters required Calls the 3 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_3OC(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,ar_n, ...
        fl_alpha,fl_theta,fl_delta,fl_kappa,fl_r,fl_w,fl_phi,fl_ahi,fl_zhi, ...
         fl_risk,it_zgridno, it_agridno,it_ngridno ...
        ] = varargin{:};

    bl_print  = false;


else
    close all;

    fl_ahi         = 5;
    fl_zhi         = 2.2;
    it_agridno     = 4;
    it_zgridno     = 5;
    it_ngridno     = 2;
    ar_a = linspace(0,fl_ahi,it_agridno);
    ar_z = linspace(1,fl_zhi,it_zgridno);
    fl_phi         = 0;
    fl_risk        = 1;
    ar_n          = [0,1];
    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 OC3

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

Computing consumption

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

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

mt_futassets=permute(mt_futassets,[4 2 3 1]);

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

neg = find(mt_con<0);
zero = find(mt_con==0);


%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) = -10^20;
mt_util(zero) = -10^10;

Printing outputs

if(bl_print)
    disp('Below is the COH matrix for for all combinations of a, z, n and future a');
    disp(mt4_coh);
    disp('Below is the future assets matrix for each combination of a, z, n and future a');
    disp(mt_futassets);
    disp('Below is the consumption matrix for for all combinations of a, z, n and future a');
    disp(mt_con);
    disp('Below is the utility matrix for for all combinations of a, z, n 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, n and future a

(:,:,1,1) =

         0         0         0         0         0
    1.9437    2.1374    2.3621    2.6155    2.8959
    3.7344    4.0396    4.3935    4.7927    5.2345
    5.4913    5.8888    6.3505    6.8713    7.4477


(:,:,2,1) =

    1.5000    1.5000    1.5000    1.5000    1.5000
    3.2500    3.2500    3.2500    3.2500    3.2500
    5.0000    5.0000    5.0000    5.0000    5.2345
    6.7500    6.7500    6.7500    6.8713    7.4477


(:,:,1,2) =

         0         0         0         0         0
    1.9437    2.1374    2.3621    2.6155    2.8959
    3.7344    4.0396    4.3935    4.7927    5.2345
    5.4913    5.8888    6.3505    6.8713    7.4477


(:,:,2,2) =

    1.5000    1.5000    1.5000    1.5000    1.5000
    3.2500    3.2500    3.2500    3.2500    3.2500
    5.0000    5.0000    5.0000    5.0000    5.2345
    6.7500    6.7500    6.7500    6.8713    7.4477


(:,:,1,3) =

         0         0         0         0         0
    1.9437    2.1374    2.3621    2.6155    2.8959
    3.7344    4.0396    4.3935    4.7927    5.2345
    5.4913    5.8888    6.3505    6.8713    7.4477


(:,:,2,3) =

    1.5000    1.5000    1.5000    1.5000    1.5000
    3.2500    3.2500    3.2500    3.2500    3.2500
    5.0000    5.0000    5.0000    5.0000    5.2345
    6.7500    6.7500    6.7500    6.8713    7.4477


(:,:,1,4) =

         0         0         0         0         0
    1.9437    2.1374    2.3621    2.6155    2.8959
    3.7344    4.0396    4.3935    4.7927    5.2345
    5.4913    5.8888    6.3505    6.8713    7.4477


(:,:,2,4) =

    1.5000    1.5000    1.5000    1.5000    1.5000
    3.2500    3.2500    3.2500    3.2500    3.2500
    5.0000    5.0000    5.0000    5.0000    5.2345
    6.7500    6.7500    6.7500    6.8713    7.4477

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

(:,:,1,1) =

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


(:,:,2,1) =

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


(:,:,1,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


(:,:,2,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


(:,:,1,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


(:,:,2,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


(:,:,1,4) =

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


(:,:,2,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, n and future a

(:,:,1,1) =

         0         0         0         0         0
    1.9437    2.1374    2.3621    2.6155    2.8959
    3.7344    4.0396    4.3935    4.7927    5.2345
    5.4913    5.8888    6.3505    6.8713    7.4477


(:,:,2,1) =

    1.5000    1.5000    1.5000    1.5000    1.5000
    3.2500    3.2500    3.2500    3.2500    3.2500
    5.0000    5.0000    5.0000    5.0000    5.2345
    6.7500    6.7500    6.7500    6.8713    7.4477


(:,:,1,2) =

   -1.6667   -1.6667   -1.6667   -1.6667   -1.6667
    0.2771    0.4707    0.6954    0.9488    1.2292
    2.0678    2.3729    2.7268    3.1261    3.5678
    3.8246    4.2221    4.6839    5.2047    5.7810


(:,:,2,2) =

   -0.1667   -0.1667   -0.1667   -0.1667   -0.1667
    1.5833    1.5833    1.5833    1.5833    1.5833
    3.3333    3.3333    3.3333    3.3333    3.5678
    5.0833    5.0833    5.0833    5.2047    5.7810


(:,:,1,3) =

   -3.3333   -3.3333   -3.3333   -3.3333   -3.3333
   -1.3896   -1.1959   -0.9713   -0.7178   -0.4374
    0.4011    0.7062    1.0602    1.4594    1.9012
    2.1579    2.5554    3.0172    3.5380    4.1143


(:,:,2,3) =

   -1.8333   -1.8333   -1.8333   -1.8333   -1.8333
   -0.0833   -0.0833   -0.0833   -0.0833   -0.0833
    1.6667    1.6667    1.6667    1.6667    1.9012
    3.4167    3.4167    3.4167    3.5380    4.1143


(:,:,1,4) =

   -5.0000   -5.0000   -5.0000   -5.0000   -5.0000
   -3.0563   -2.8626   -2.6379   -2.3845   -2.1041
   -1.2656   -0.9604   -0.6065   -0.2073    0.2345
    0.4913    0.8888    1.3505    1.8713    2.4477


(:,:,2,4) =

   -3.5000   -3.5000   -3.5000   -3.5000   -3.5000
   -1.7500   -1.7500   -1.7500   -1.7500   -1.7500
         0         0         0         0    0.2345
    1.7500    1.7500    1.7500    1.8713    2.4477

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

(:,:,1,1) =

   1.0e+10 *

   -1.0000   -1.0000   -1.0000   -1.0000   -1.0000
    0.0000    0.0000    0.0000    0.0000    0.0000
    0.0000    0.0000    0.0000    0.0000    0.0000
    0.0000    0.0000    0.0000    0.0000    0.0000


(:,:,2,1) =

    0.4055    0.4055    0.4055    0.4055    0.4055
    1.1787    1.1787    1.1787    1.1787    1.1787
    1.6094    1.6094    1.6094    1.6094    1.6553
    1.9095    1.9095    1.9095    1.9274    2.0079


(:,:,1,2) =

   1.0e+20 *

   -1.0000   -1.0000   -1.0000   -1.0000   -1.0000
   -0.0000   -0.0000   -0.0000   -0.0000    0.0000
    0.0000    0.0000    0.0000    0.0000    0.0000
    0.0000    0.0000    0.0000    0.0000    0.0000


(:,:,2,2) =

   1.0e+20 *

   -1.0000   -1.0000   -1.0000   -1.0000   -1.0000
    0.0000    0.0000    0.0000    0.0000    0.0000
    0.0000    0.0000    0.0000    0.0000    0.0000
    0.0000    0.0000    0.0000    0.0000    0.0000


(:,:,1,3) =

   1.0e+20 *

   -1.0000   -1.0000   -1.0000   -1.0000   -1.0000
   -1.0000   -1.0000   -1.0000   -1.0000   -1.0000
   -0.0000   -0.0000    0.0000    0.0000    0.0000
    0.0000    0.0000    0.0000    0.0000    0.0000


(:,:,2,3) =

   1.0e+20 *

   -1.0000   -1.0000   -1.0000   -1.0000   -1.0000
   -1.0000   -1.0000   -1.0000   -1.0000   -1.0000
    0.0000    0.0000    0.0000    0.0000    0.0000
    0.0000    0.0000    0.0000    0.0000    0.0000


(:,:,1,4) =

   1.0e+20 *

   -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   -1.0000   -0.0000
   -0.0000   -0.0000    0.0000    0.0000    0.0000


(:,:,2,4) =

   1.0e+20 *

   -1.0000   -1.0000   -1.0000   -1.0000   -1.0000
   -1.0000   -1.0000   -1.0000   -1.0000   -1.0000
   -0.0000   -0.0000   -0.0000   -0.0000   -0.0000
    0.0000    0.0000    0.0000    0.0000    0.0000