function [ years_sample ] = plot_xt_index( xt_adv, xt_mid, xt_poor, index_adv, index_mid, index_poor)

%SPECIFIC FUNCTION!!!!!!!!!

% PURPOSE: PLOT ALL COUNTRIES CYCLICAL COMPONENT OF THE OVERALL INDEX AND THE OUTPUT GAP
% DIVIDED BY INCOME GROUPS
% 
% INPUT:
%     -xt_adv: OUTPUT GAP ADVANCED ECONOIES
%     -xt_mid: OUTPUT GAP EMERGING MARKETS
%     -xt_poor: OUTPUT GAP DEVELOPING ECONOMIES
%     -index_adv: CYCLICAL COMPONENT OVERALL INDEX ADVANCED ECONOMIES
%     -index_mid: CYCLICAL COMPONENT OVERALL INDEX EMERGING MARKETS
%     -index_poor: CYCLICAL COMPONENT OVERALL INDEX DEVELOPING ECONOMIES


close all

%Recall variables defined in the main script
global schindler_years Countries num_adv num_mid num_poor

%Define time horizon
years_sample=[1995 1998 2002 2006 2011]';
label_y = [-1 0 1];

%Define country names groups
[Countries_adv, Countries_mid, Countries_poor] = country_groups(1, Countries);

figure(1)
for i=1:12
subplot(4,3,i)
[haxes,hline1,hline2] = plotyy(index_adv(i,:,2), 'b-+', xt_adv(i,:) ,'r-*','plot');
set(haxes, 'xTickLabel','')
set(gca, 'XTick', 1:4:schindler_years, 'XTickLabel', years_sample,'FontSize',10);
xlabel('Years');
set(haxes(1), 'yTickLabel','')
set(haxes(1), 'yLim',[-1 1])
set(haxes(1),'YTick',[-1 0 1], 'YTickLabel', label_y,'FontSize',10);
t=title(Countries_adv(i,1),'FontWeight','bold');
set(t,'FontSize',8);
hold on
set(haxes(1),'Nextplot','add');
hline3=plot(index_adv(i,:,3),'k-o');
hold off
box off
end
legend1 = legend([hline2 hline1 hline3],'Output Gap','Inflows Index','Outflows Index');
set(legend1,'Orientation','horizontal','Position',[0.421614583333333 0.0341545893719807 0.178645833333333 0.0244444444444444],'FontSize',8, 'Box','off');
ha = axes('Visible','off','Position',[0 0 1 1]);
text('Parent',ha,'String','\bf Figure A.4. Output and Capital Controls: All Countries','Position',[0.508203125 0.978604294478528 9.16025403784439],'HorizontalAlignment','center');
sub_ha = axes('Visible','off','Position',[0 0 1 1]);
text('Parent',sub_ha,'String','\bf Advanced Economies','Position',[0.516015625 0.9605 9.16025403784439],'HorizontalAlignment','center');

%print( figure(1), 'FigureA4a','-dpdf');

figure(2)
for i=13:num_adv
subplot(4,3,i-12)
[haxes,hline1,hline2] = plotyy(index_adv(i,:,2), 'b-+', xt_adv(i,:) ,'r-*','plot');
set(haxes, 'xTickLabel','')
set(gca, 'XTick', 1:4:schindler_years, 'XTickLabel', years_sample,'FontSize',10);
xlabel('Years');
set(haxes(1), 'yTickLabel','')
set(haxes(1), 'yLim',[-1 1])
set(haxes(1),'YTick',[-1 0 1], 'YTickLabel', label_y,'FontSize',10);
t=title(Countries_adv(i,1),'FontWeight','bold');
set(t,'FontSize',8);
hold on
set(haxes(1),'Nextplot','add');
hline3=plot(index_adv(i,:,3),'k-o');
hold off
box off
end
legend1 = legend([hline2 hline1 hline3],'Output Gap','Inflows Index','Outflows Index');
set(legend1,'Orientation','horizontal','Position',[0.421614583333333 0.0341545893719807 0.178645833333333 0.0244444444444444],'FontSize',8, 'Box','off');
sub_ha = axes('Visible','off','Position',[0 0 1 1]);
text('Parent',sub_ha,'String','\bf Advanced Economies','Position',[0.516015625 0.9605 9.16025403784439],'HorizontalAlignment','center');

%print( figure(2), 'FigureA4b','-dpdf');

figure(3)
for i=1:12
subplot(4,3,i)
[haxes,hline1,hline2] = plotyy(index_mid(i,:,2), 'b-+', xt_mid(i,:) ,'r-*','plot');
set(haxes, 'xTickLabel','')
set(gca, 'XTick', 1:4:schindler_years, 'XTickLabel', years_sample,'FontSize',10);
xlabel('Years');
set(haxes(1), 'yTickLabel','')
set(haxes(1), 'yLim',[-1 1])
set(haxes(1),'YTick',[-1 0 1], 'YTickLabel', label_y,'FontSize',10);
t=title(Countries_mid(i,1),'FontWeight','bold');
set(t,'FontSize',8);
hold on
set(haxes(1),'Nextplot','add');
hline3=plot(index_mid(i,:,3),'k-o');
hold off

box off
end
legend1 = legend([hline2 hline1 hline3],'Output Gap','Inflows Index','Outflows Index');
set(legend1,'Orientation','horizontal','Position',[0.421614583333333 0.0341545893719807 0.178645833333333 0.0244444444444444],'FontSize',8, 'Box','off');
sub_ha = axes('Visible','off','Position',[0 0 1 1]);
text('Parent',sub_ha,'String','\bf Emerging Markets','Position',[0.516015625 0.9605 9.16025403784439],'HorizontalAlignment','center');

%print(figure(3), 'FigureA4c','-dpdf');

figure(4)
for i=13:24
subplot(4,3,i-12)
[haxes,hline1,hline2] = plotyy(index_mid(i,:,2), 'b-+', xt_mid(i,:) ,'r-*','plot');
set(haxes, 'xTickLabel','')
set(gca, 'XTick', 1:4:schindler_years, 'XTickLabel', years_sample,'FontSize',10);
xlabel('Years');
set(haxes(1), 'yTickLabel','')
set(haxes(1), 'yLim',[-1 1])
set(haxes(1),'YTick',[-1 0 1], 'YTickLabel', label_y,'FontSize',10);
t=title(Countries_mid(i,1),'FontWeight','bold');
set(t,'FontSize',8);
hold on
set(haxes(1),'Nextplot','add');
hline3=plot(index_mid(i,:,3),'k-o');
hold off
box off
end
legend1 = legend([hline2 hline1 hline3],'Output Gap','Inflows Index','Outflows Index');
set(legend1,'Orientation','horizontal','Position',[0.421614583333333 0.0341545893719807 0.178645833333333 0.0244444444444444],'FontSize',8, 'Box','off');
sub_ha = axes('Visible','off','Position',[0 0 1 1]);
text('Parent',sub_ha,'String','\bf Emerging Markets','Position',[0.516015625 0.9605 9.16025403784439],'HorizontalAlignment','center');

%print(figure(4), 'FigureA4d','-dpdf');

figure(5)
for i=25:num_mid
subplot(4,3,i-24)
[haxes,hline1,hline2] = plotyy(index_mid(i,:,2), 'b-+', xt_mid(i,:) ,'r-*','plot');
set(haxes, 'xTickLabel','')
set(gca, 'XTick', 1:4:schindler_years, 'XTickLabel', years_sample,'FontSize',10);
xlabel('Years');
set(haxes(1), 'yTickLabel','')
set(haxes(1), 'yLim',[-1 1])
set(haxes(1),'YTick',[-1 0 1], 'YTickLabel', label_y,'FontSize',10);
t=title(Countries_mid(i,1),'FontWeight','bold');
set(t,'FontSize',8);
hold on
set(haxes(1),'Nextplot','add');
hline3=plot(index_mid(i,:,3),'k-o');
hold off
box off
end
legend1 = legend([hline2 hline1 hline3],'Output Gap','Inflows Index','Outflows Index');
set(legend1,'Orientation','horizontal','Position',[0.421614583333333 0.0341545893719807 0.178645833333333 0.0244444444444444],'FontSize',8, 'Box','off');
sub_ha = axes('Visible','off','Position',[0 0 1 1]);
text('Parent',sub_ha,'String','\bf Emerging Markets','Position',[0.516015625 0.9605 9.16025403784439],'HorizontalAlignment','center');

%print(figure(5), 'FigureA4e','-dpdf');

figure(6)
for i=1:12
subplot(4,3,i)
[haxes,hline1,hline2] = plotyy(index_poor(i,:,2), 'b-+', xt_poor(i,:) ,'r-*','plot');
set(haxes, 'xTickLabel','')
set(gca, 'XTick', 1:4:schindler_years, 'XTickLabel', years_sample,'FontSize',10);
xlabel('Years');
set(haxes(1), 'yTickLabel','')
set(haxes(1), 'yLim',[-1 1])
set(haxes(1),'YTick',[-1 0 1], 'YTickLabel', label_y,'FontSize',10);
t=title(Countries_poor(i,1),'FontWeight','bold');
set(t,'FontSize',8);
hold on
set(haxes(1),'Nextplot','add');
hline3=plot(index_poor(i,:,3),'k-o');
hold off
box off
end
legend1 = legend([hline2 hline1 hline3],'Output Gap','Inflows Index','Outflows Index');
set(legend1,'Orientation','horizontal','Position',[0.421614583333333 0.0341545893719807 0.178645833333333 0.0244444444444444],'FontSize',8, 'Box','off');
sub_ha = axes('Visible','off','Position',[0 0 1 1]);
text('Parent',sub_ha,'String','\bf Low-Income Countries','Position',[0.516015625 0.9605 9.16025403784439],'HorizontalAlignment','center');

%print(figure(6), 'FigureA4f','-dpdf');

figure(7)
for i=13:num_poor
subplot(4,3,i-12)
[haxes,hline1,hline2] = plotyy(index_poor(i,:,2), 'b-+', xt_poor(i,:) ,'r-*','plot');
set(haxes, 'xTickLabel','')
set(gca, 'XTick', 1:4:schindler_years, 'XTickLabel', years_sample,'FontSize',10);
xlabel('Years');
set(haxes(1), 'yTickLabel','')
set(haxes(1), 'yLim',[-1 1])
set(haxes(1),'YTick',[-1 0 1], 'YTickLabel', label_y,'FontSize',10);
t=title(Countries_poor(i,1),'FontWeight','bold');
set(t,'FontSize',8);
hold on
set(haxes(1),'Nextplot','add');
hline3=plot(index_poor(i,:,3),'k-o');
hold off
box off
end
legend1 = legend([hline2 hline1 hline3],'Output Gap','Inflows Index','Outflows Index');
set(legend1,'Orientation','horizontal','Position',[0.367447916666666 0.2283607872222 0.304166666666667 0.0322147651006711],'FontSize',8,'Box','off');
sub_ha = axes('Visible','off','Position',[0 0 1 1]);
text('Parent',sub_ha,'String','\bf Low-Income Countries','Position',[0.516015625 0.9605 9.16025403784439],'HorizontalAlignment','center');

%print(figure(7), 'FigureA4g','-dpdf');

end

