Stationary distribution of assets - 3OC
This function solves the stationary distribution of assets 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 function hhsave_VFI_3OC.m
Function Outputs :
Contents
function [mt_dis, mt_o, mt_k, mt_l]= hhsave_dis_3OC(varargin)
addpath(genpath('/Users/sidhantkhanna/Desktop/Research/Matlab Code/My codes')); close all; bl_profile = false; % Switch off profile if running a tester/calling from another function bl_saveimg = false; if(bl_profile) profile off; profile on; end addpath(genpath('/Users/sidhantkhanna/Documents/GitHub/BKS modified/')); 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,mt_trans_z,mt_trans_n,fl_beta, fl_mu_z, fl_sig_z,fl_rho_z,... fl_lambda_z,fl_mu_n, fl_sig_n,fl_rho_n,fl_lambda_n, fl_tolvfi, fl_toldis ... ] = varargin{:}; bl_print = false; bl_plot = false; else fl_ahi = 10; fl_zhi = 2; it_agridno = 10; it_zgridno = 7; it_ngridno = 2; ar_a = linspace(0,fl_ahi,it_agridno); fl_phi = 1; fl_risk = 1.5; fl_alpha = 0.4; fl_theta = 0.79-fl_alpha; fl_delta = 0.05; fl_kappa = 0; fl_mu_z = 0; % mean of AR(1) entrepeneurial productivity process fl_rho_z = 0.9; % persistence parameter of the AR(1) entrepreneurial productivity process fl_sig_z = 0.2; fl_lambda_z = 3; fl_mu_n = 0; % mean of AR(1) entrepeneurial productivity process fl_rho_n = 0.9; % persistence parameter of the AR(1) entrepreneurial productivity process fl_sig_n = 0.2; fl_lambda_n = 3; fl_beta = 0.92; [ar_z, mt_trans_z] = mytauchen_z(fl_mu_z,fl_rho_z,fl_sig_z,it_zgridno,fl_lambda_z); ar_z = exp(ar_z)'; mt_trans_n =[0.7,0.3;0.7,0.3]; ar_n =[0,1]; [fl_r,fl_w] = ... deal(0.05,1.5); fl_tolvfi = 10^-12; bl_print = true; fl_toldis = 10^-12; % Tolerance level for convergence stationary distribution end fl_R = fl_r + fl_delta; it_s=1; % Counting iteration for Convergence to Stationary Distribution fl_sum1(1)=0; % Variable to check if all elements of Stationary distribution Sum to 1 fl_crit1=1; % Calling VFI [mt_vf, mt_pf, mt_oploc, mt_o, mt_k, mt_l]=hhsave_VFI_3OC(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, mt_trans_z,mt_trans_n,fl_beta, fl_mu_z, fl_sig_z,fl_rho_z, ... fl_lambda_z,fl_mu_n, fl_sig_n,fl_rho_n,fl_lambda_n, fl_tolvfi ... );
Evaluating Stationary Distribution
it_s=1; % Counting iteration for Convergence to Stationary Distribution fl_sum1(1)=0; % Variable to check if all elements of Stationary distribution Sum to 1 fl_crit1=1; P(:,:,:,(it_s+1))=zeros(it_agridno,it_zgridno,it_ngridno); P(:,:,:,1)=ones(it_agridno,it_zgridno,it_ngridno).*(1/(it_agridno*it_zgridno*it_ngridno)); while(fl_crit1>fl_toldis) P(:,:,:,it_s+1)=zeros(it_agridno,it_zgridno,it_ngridno); for i= 1:it_agridno for j= 1:it_zgridno for c= 1:it_ngridno f=find((ar_a==mt_pf(i,j,c))); for g=1:it_zgridno for h = 1: it_ngridno P(f,g,h,it_s+1)= P(f,g,h,it_s+1)+ mt_trans_z(j,g)*mt_trans_n(c,h)*P(i,j,c,it_s); %evaluates Probability in a particular row and column in the next period end end end end end fl_sum1(it_s+1)=sum(sum(sum(P(:,:,:,it_s+1)))); % sum of all elements of the matrix P(:,:,s) in a particular iteration, which must be equal to 1 for all s % we observe that the vector sum1 has value 1 in all the cells on running the code mt_diff1=(P(:,:,:,it_s+1)- P(:,:,:,it_s)); mt_diff1 = mt_diff1(:); fl_crit1=norm(mt_diff1); it_s=it_s+1; end fl_Ea=sum(sum(P(:,:,:,it_s),2).*ar_a'); mt_dis=P(:,:,:,it_s);
Printing outputs
if(bl_print) disp('Below is the Stationary Distribution'); disp((mt_dis)); st_ar_a = strsplit(num2str(ar_a)); for i=1:it_agridno st_a(i) =strcat('a=', st_ar_a(i)); end disp('Table for Stationary Distribution at l=0'); tb_dis = array2table(mt_dis(:,:,1),'VariableNames',{'z1','z2','z3','z4','z5','z6','z7'}); tb_dis.Properties.RowNames = st_a; disp(tb_dis); disp('Table for Stationary Distribution at l=1'); tb_dis = array2table(mt_dis(:,:,1),'VariableNames',{'z1','z2','z3','z4','z5','z6','z7'}); tb_dis.Properties.RowNames = st_a; disp(tb_dis); end if(bl_profile) profile off; profile viewer; st_file_name = '/Users/sidhantkhanna/Documents/GitHub/BKS modified/code/Profile/Households/hhsave_dis_3OC'; profsave(profile('info'), st_file_name); end
Below is the Stationary Distribution (:,:,1) = 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 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0008 0.0110 0.0516 0.0243 0.0022 0.0000 0.0000 0.0030 0.0219 0.0407 0.0638 0.0112 0.0002 0.0000 0.0023 0.0107 0.0259 0.0353 0.0131 0.0010 0.0000 0.0022 0.0065 0.0181 0.0276 0.0134 0.0011 0.0000 0.0008 0.0037 0.0140 0.0271 0.0136 0.0011 0.0000 0.0003 0.0021 0.0105 0.0309 0.0146 0.0012 0.0000 0.0002 0.0011 0.0047 0.0270 0.0974 0.0524 0.0096 (:,:,2) = 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 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0003 0.0047 0.0221 0.0104 0.0009 0.0000 0.0000 0.0013 0.0094 0.0174 0.0273 0.0048 0.0001 0.0000 0.0010 0.0046 0.0111 0.0151 0.0056 0.0004 0.0000 0.0009 0.0028 0.0077 0.0118 0.0057 0.0005 0.0000 0.0003 0.0016 0.0060 0.0116 0.0058 0.0005 0.0000 0.0001 0.0009 0.0045 0.0133 0.0062 0.0005 0.0000 0.0001 0.0005 0.0020 0.0116 0.0417 0.0225 0.0041 Table for Stationary Distribution at l=0 z1 z2 z3 z4 z5 z6 z7 __________ __________ __________ __________ __________ __________ __________ a=0 1.112e-24 5.6643e-24 1.2807e-23 1.1184e-23 1.4788e-24 3.3944e-27 5.7025e-32 a=1.11111 5.9976e-23 3.0568e-22 6.918e-22 6.0555e-22 8.1681e-23 3.7023e-25 2.7094e-28 a=2.22222 1.6061e-21 8.1904e-21 1.8554e-20 1.628e-20 2.2411e-21 1.5158e-23 1.4761e-26 a=3.33333 0.00080977 0.011036 0.051586 0.024285 0.0021741 4.923e-06 8.2691e-11 a=4.44444 0.0030045 0.021867 0.040706 0.063793 0.011231 0.00020527 2.6336e-07 a=5.55556 0.0023054 0.010671 0.025853 0.035265 0.013108 0.0009569 1.3587e-06 a=6.66667 0.0022066 0.0064608 0.018078 0.027611 0.013367 0.0011124 1.5858e-06 a=7.77778 0.00079252 0.0037492 0.014015 0.027096 0.013605 0.0011344 1.6172e-06 a=8.88889 0.00033607 0.002078 0.010532 0.030939 0.014572 0.0011562 1.6459e-06 a=10 0.00015112 0.0011014 0.0046821 0.026968 0.097395 0.052394 0.0095995 Table for Stationary Distribution at l=1 z1 z2 z3 z4 z5 z6 z7 __________ __________ __________ __________ __________ __________ __________ a=0 1.112e-24 5.6643e-24 1.2807e-23 1.1184e-23 1.4788e-24 3.3944e-27 5.7025e-32 a=1.11111 5.9976e-23 3.0568e-22 6.918e-22 6.0555e-22 8.1681e-23 3.7023e-25 2.7094e-28 a=2.22222 1.6061e-21 8.1904e-21 1.8554e-20 1.628e-20 2.2411e-21 1.5158e-23 1.4761e-26 a=3.33333 0.00080977 0.011036 0.051586 0.024285 0.0021741 4.923e-06 8.2691e-11 a=4.44444 0.0030045 0.021867 0.040706 0.063793 0.011231 0.00020527 2.6336e-07 a=5.55556 0.0023054 0.010671 0.025853 0.035265 0.013108 0.0009569 1.3587e-06 a=6.66667 0.0022066 0.0064608 0.018078 0.027611 0.013367 0.0011124 1.5858e-06 a=7.77778 0.00079252 0.0037492 0.014015 0.027096 0.013605 0.0011344 1.6172e-06 a=8.88889 0.00033607 0.002078 0.010532 0.030939 0.014572 0.0011562 1.6459e-06 a=10 0.00015112 0.0011014 0.0046821 0.026968 0.097395 0.052394 0.0095995