 # Matlab plotting function

Hi Professor

I am have a bit of trouble plotting data with matlab …
The data is quartely, and starts from 1986Q4 to 2016Q4,
and I want to specify time axis with Matlab…

clear all; close all; clc;

k=0;

for i=1986:2016;
if i==1986
quarters=;
else
quarters=[3 6 9 12];
end

``````    for j=quarters
k=k+1;
T(k,1)=datenum(i,j,1);
end
``````

end

plot(T,a1,‘b’,‘LineWidth’,2);
set(gca,‘XTick’,[T(1):365*1:T(end)]);
datetick(‘x’,‘yy’,‘keepticks’);
recessionplot;
ax = gca;
ax.YAxis.Exponent=0;
set(gca,‘FontSize’,14, ‘FontName’,‘Times’);

However, when specifying dates as shown below in “test.m”, the plot I got isn’t exactly correct.

From the plot below, it looks like the data starts from somewhere in 86 and ends in 15Q4….
Please could you indicate me the problem??

Q2. the “recessionplot” build-in function with Matlab is based on the US data. However, if I want to customize it for the EU data or UK data, how am I suppossed to mofify the “recessionplot” part?

say, if I want to specify the recession for the UK as 2008Q1-2009Q1, how am I supposed to modify my clode?

a1.csv (1.1 KB) test.m (456 Bytes)

1. This is due to Matlab changing the xlim. You need to preserve the limits. The following works:
``````clear all; close all; clc;
T=size(a1,1);

dates=datenum([1986;kron([1987:2016]',ones(4,1))],[10;repmat([1:3:10]',30,1)],ones(T,1));

figure;
plot(dates,a1,'b','LineWidth',2);
hh=gca;
axis tight
set(gca,'Xtick',dates(2:4:end-4))
set(gca,'XtickLabel',dates(2:4:end-4))
datetick('x','yy','keepticks','keeplimits');
recessionplot;
ax = gca;
ax.YAxis.Exponent=0;
set(gca,'FontSize',14, 'FontName','Times');`
``````
1. The dates of recessions can be passed using the `'recessions' — Recession data` name/value pair of the function. See the Matlab help.

Professor,
Q1, the code gave me:

with the datatick of last year 2016 missing (data spans 1986Q4-2016Q4)

when I tried to modify “set(gca,‘XtickLabel’,dates(2:4:end-4))” to “set(gca,‘XtickLabel’,dates(2:4:end))”, it gave me:

the duration of the year 2016 was shorter than those of previous years, like 2015…

so I think there might be some problems…

besides, if I want to plot the time interval as 2 years, how am I supposed to modify the code?
I tried to modify “set(gca,‘Xtick’,dates(2:4:end-4))
set(gca,‘XtickLabel’,dates(2:4:end-4))” to "set(gca,‘Xtick’,dates(2:8:end-4))
set(gca,‘XtickLabel’,dates(2:8:end-4)), but only got:

Of course 2016 it is shorter, because the data ends before 2017. That is also the reason it is not shown.

1 Like

hi professor,

In Small-Open-Economy framework where domestic households have access to both domestic (B) and foreign bonds ( B_*).

would the debt/gdp ratio be defined as B/Y?

That question is not well-defined. Which debt/GDP ratio are you referring to? Net or gross? Private or public? External or total?

I was referring to public debt, assuming that the households have access to both domestic and foreign bonds.
Thanks

If you consider total public debt and the government issues that debt domestically and internationally, you want to have internal and external debt. So you need to add B and B^* (and potentially transform them to the same units)

1 Like

Hi Professor,

further to my previous question,
If I want to plot every 3 years on x-axis (data label), e.g. 1987,1990,1993,1996…how am I supposed to modify the codes below:

clear all; close all; clc;
T=size(a1,1);

dates=datenum([1986;kron([1987:2016]’,ones(4,1))],[10;repmat([1:3:10]’,30,1)],ones(T,1));

figure;
plot(dates,a1,‘b’,‘LineWidth’,2);
hh=gca;
axis tight
set(gca,‘Xtick’,dates(2:4:end-4))
set(gca,‘XtickLabel’,dates(2:4:end-4))
datetick(‘x’,‘yy’,‘keepticks’,‘keeplimits’);
recessionplot;
ax = gca;
ax.YAxis.Exponent=0;
set(gca,‘FontSize’,14, ‘FontName’,‘Times’);