Adding Recession Bars to a line plot

8 visualizaciones (últimos 30 días)
Parveshsingh Seeballack
Parveshsingh Seeballack el 1 de Nov. de 2018
Comentada: dpb el 10 de Nov. de 2018
Hi all
I am trying to figure out how to add NBER recession bars to my graph.
I understand that I need to format my date correctly using datenum for the recessionplot function to work.
To summarise, I am running a rolling regression. The date vector (datevec) has been generated using a rolling vector created in my code. Once I've got my coefficient (timevardelta + standard error bands) I am graphing it against the datevec.
Now I understand that the format of the datevec is not appropriate to use recessionplot.
Below is the code I am using for my graph:
clear all, clc
load datevec
load adjtimevarsd
load timevardelta
% Plot rolling regression results in Figure 1:
figure(1); clf ;
plot(datevec,timevardelta','LineWidth',1.5) ;
hold on ;
plot(datevec,timevardelta'+1.96*adjtimevarsd',':','Color',[.4 .4 .4],'LineWidth',1.5) ;
plot(datevec,timevardelta'-1.96*adjtimevarsd',':','Color',[.4 .4 .4],'LineWidth',1.5) ;
plot(datevec,ones(size(datevec)),'k', datevec, zeros(size(datevec)),'k') ;
ylim = get(gca,'YLim') ;
axis([2005, 2016.05, -0.50, 3.00]) ;
ylim = get(gca,'YLim') ;
xlim = get(gca,'XLim');
% redraw lines, tick marks, and axis lines
plot(datevec,timevardelta','LineWidth',1.5) ;
plot(datevec,timevardelta'+1.96*adjtimevarsd',':','Color',[.4 .4 .4],'LineWidth',1.5) ;
plot(datevec,timevardelta'-1.96*adjtimevarsd',':','Color',[.4 .4 .4],'LineWidth',1.5) ;
plot(datevec,ones(size(datevec)),'k', datevec, zeros(size(datevec)),'k') ;
ticks = get(gca,'XTick') ;
for tick = ticks ;
plot([tick,tick],[ylim(1),ylim(1)+.015*(ylim(2)-ylim(1))],'k') ;
plot([tick,tick],[ylim(2),ylim(2)-.015*(ylim(2)-ylim(1))],'k') ;
end ;
plot([xlim(1),xlim(2)],[ylim(1),ylim(1)],'k') ;
plot([xlim(1),xlim(2)],[ylim(2),ylim(2)],'k') ;
plot([xlim(1),xlim(1)],[ylim(1),ylim(2)],'k') ;
plot([xlim(2),xlim(2)],[ylim(1),ylim(2)],'k') ;
hold off ;
I have provided the data files, for your consideration.
I would be very grateful if you could please help me through (any hints, tips...anything!) how to graph NBER recession bars on my graph.
Thank you all.
Regards Parvesh
  11 comentarios
Parveshsingh Seeballack
Parveshsingh Seeballack el 9 de Nov. de 2018
I have an issue when trying to plot a graph and overaly recession bar on it when changing the rollby value.
The code runs ok when the rollby equal to 1, i.e. I am performing daily rolling regressions.
However, when I change rollby to, say, 10. The code for graphing the coefficient does not work.
I get the following error:
Error using plot
Vectors must be the same length.
Error in Mutivariate_30Mins (line 173)
plot(dn,timevardelta','LineWidth',1.5)
It appears that I am missing a line of code that adjusts the x-axis values for date when rolling window changes; so, my issue is kind of understandable because Matlab cannot figure out that the date vector has changed to the fact that the rolling window has changed.
Any tip around how to get past this issue?
Thank you in advance for your help.
PS:
The dates have gaps.
I cannot keep the whole dataset as I have 4.8 million plus observations and it would be difficult to run an nls regression if I keep the full length of my dataset.
dpb
dpb el 10 de Nov. de 2018
That says you've not selected the same number of elements from the two variables. It looks like your plot statement hasn't been modified to use a subset of the full time array dn x variable commensurate with the y variable.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Time Series Objects en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by