%plotd_xi83.m produces Figure 10 (Unconditional Distribution of Debt, $\xi=0.83$) 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_xi83', 'ramsey_1122018_xi83'};
%produced by running simu('constrained_152018ab_xi83')

nf = numel(fname); 
ltype ={'b-.','r-'};
legen = {'Competitive Economy','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) std(D) mean(CT) std(CT)]]; 

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', 'NE')

set(gca, 'XLim', [0.8 1.1]);

hold off


shg