% statistics.m
% this file computes the statistics and the debt distribution
% compute trade balance as fraction of output
TB_Y = (Ytilde - C)./Ytilde;
% bad financial standing (BFS): either default in current period F==1 or bad
% standing after signal B==1
x_bad = find(F==1|B==1);
% good financial standing (GFS): those who are in good financial standing (B==0)
% and do not default (F==0)
x_good = find(F==0&B==0);
% average per-period loss of BFS as share of total output, conditional on BFS
loss = mean((Y(x_bad)-Ytilde(x_bad))./Y(x_bad));
% default frequency
def_freq = mean(F)*4*100;
% other variables needed
dy = D(x_good)./Ytilde(x_good); % debt/output
pm = PM(x_good); % country premium
tb = TB_Y(x_good); % trade balance over output
temp1 = corrcoef(pm,Ytilde(x_good));
corr_pm_y = temp1(2,1); % correlation risk premium and output
temp2 = corrcoef(pm,tb);
corr_pm_tb = temp2(2,1); % correlation risk premium and trade balance over output
Statistics = table;
Statistics.Av_loss = loss*100;
Statistics.Def_prob = def_freq;
Statistics.Mean_dy = mean(dy)*100;
Statistics.Mean_prem = mean(pm);
Statistics.SD_prem = std(pm);
Statistics.Rho_prem_y = corr_pm_y;
Statistics.Rho_prem_tb = corr_pm_tb;
Statistics