%plotd.m produces Figure 7 (Unconditional Distribution of Debt, $\xi=0.5$) in 
%``Multiple Equilibria in Open Economies with  Collateral Constraints,''  
% by Stephanie Schmitt-Grohé and Martín Uribe. 
%©  Stephanie Schmitt-Grohé and Martín Uribe, January 2018.

clear all
clf

ww=20;% smoothing parameter
dick=2; %thickness of linewidth for graphing

fname = {'constrained_152018ab',  'constrained_152018b', 'constrained_152018c', 'ramsey_1122018'};
%produced by running simu('constrained_152018ab')
%the input, constrained_152018ab.mat, is produced by running constrained_152018.m  and by setting
% eqm_selection_criterion = 'ab';
%same for 'ac', 'b', and 'c'. Or ramsey_1122018.m

nf = numel(fname); 
ltype ={'b--', 'b:','b-.','r-'};
legen = {'Criterion (A)','Criterion (B)','Criterion (C)','Ramsey Equilibrium'};

table =[];

for i = 1:nf
    
eval(['load simu_' fname{i} '.mat  lad dgrid EDY CRISIS D CT rstar'])

table = [table; [100*EDY/(1+rstar) mean(CRISIS) mean(D) quantile(D,[0.01 0.05 0.5 ]) skewness(D)] ]; 

lad = movlad(lad, ww);
dgrid=movlad(dgrid,ww);
dd=dgrid(2)-dgrid(1); 
plot(dgrid , lad/dd,ltype{i}, 'linewidth',dick)


hold on 
end
xlabel('$d_t$', 'Interpreter','LaTeX')
ylabel('Density', 'Interpreter', 'LaTeX')
legend(legen, 'Location', 'NW')

set(gca, 'XLim', [0.78 0.98]);

hold off

