Adding Recession Bars to a line plot
14 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
dpb
2018 年 11 月 10 日
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.
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Title についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!