% var_model_versus_data.m
%plot country-level variances of output explained by terms-of-trade shocks implied by the SVAR and MXN models studied in the paper ``How Important Are Terms Of Trade Shocks? by  Stephanie  Schmitt-Grohe and Martín Uribe.
% ©  Stephanie Schmitt-Grohe and Martin Uribe, 2016. 

clear all

load mxn_var_ir.mat   var_model_tot_ratio_cbc var_data_tot_ratio_cbc country_name
%produced by running
% mxn_var_ir.m in the directory
% Z:\uribe\tot\IER\mfiles\mxn_with_spread


tb_data = var_data_tot_ratio_cbc(3,:); 

tb_model = var_model_tot_ratio_cbc(3,:); 

y_data = var_data_tot_ratio_cbc(4,:); 

y_model = var_model_tot_ratio_cbc(4,:); 

c_data = var_data_tot_ratio_cbc(5,:); 

c_model = var_model_tot_ratio_cbc(5,:); 

ivv_data = var_data_tot_ratio_cbc(6,:); 

ivv_model = var_model_tot_ratio_cbc(6,:); 

rer_data = var_data_tot_ratio_cbc(7,:); 

rer_model = var_model_tot_ratio_cbc(7,:); 


figure(1)
clf 
plot(y_data*100, min(60,y_model*100),'.')
hold on
plot([0 60], [0 60])
ylim([0 60])
xlim([0 60])
axis('square')
corr(y_data(:), y_model(:))
disp('pausing')
pause
A = country_name; 
B = cellfun(@(x) x(1:3),A,'un',0);
C = cellstr(B);
text(y_data*100, min(60,y_model*100), B);

text(57,57, '45^o')
xlabel('SVAR Model')
ylabel('MXN Model')
set(gca,'XTick', [0 10 20 30 40 50 60])
set(gca,'YTick', [0 10 20 30 40 50 60])

data={c_data, ivv_data, rer_data, tb_data} ;
model = {c_model, ivv_model, rer_model, tb_model};
TITLE = {'Consumption', 'Investment', 'Real Exchange Rate', 'Trade Balance'};


figure(2)
clf
for i = 1:4
    subplot(2,2,i)
    plot(data{i}*100, min(60,model{i}*100),'.')
    corr(data{i}(:), model{i}(:))
    hold on
    plot([0 60], [0 60])
    ylim([0 60])
    xlim([0 60])
    set(gca,'XTick', [0 20 40  60])
    set(gca,'YTick', [0 20 40 60])
    text(50,50, '45^o')
    axis('square')
    title(TITLE{i})
    xlabel('SVAR Model')
    ylabel('MXN Model')
end
