During the past twenty years, the US monetary policy has been characterized by an alternance of easing and tightening cycles. We can easily distinguish five cycles. The tightening cycles are found before the GFC, during the Taper Tantrum, and during the most recent post-COVID-19 tightening. The easing cycles are found during the GFC and during the COVID-19 pandemics. Let me show how to produce the following graph in Stata with a few lines of codes. We are going to leverage my previous blog on shaded area for NBER recessions. Let us reproduce the following figure:
Let us look at each part of the code to understand the logic. The first part of the code aims at downloading the Fed fund rates from the FRED website. See the following blog for wide coverage of the command and use import fred. The /* */ means that this part of the code is optional. You have to download the Fed fund rates only once, unless you want to update the graph. I may add that I used the mofd() function in order to have the months in the Stata format:
// FEDFUNDS data from FRED
/*
*set fredkey 'yourkey', permanently
import fred FEDFUNDS, clear
generate datem = mofd(daten)
tsset datem, monthly
rename datem period
drop datestr daten
order period FEDFUNDS
save FEDFUNDS.dta, replace
*/
In the second part of the blog, we use financial data gathered for an ADB project and merge them with the Fed fund rates. We keep the US with keep imfcode == 111 and focus on cycles after 2004 with keep if period>=tm(2004m1). With the tsline command, I plot a time-series graph of the Wu-Xia shadow rate and the Fed funds. I also used tlabel option with the sub-option format to get a nice format for the date. The use of the pound delimiter ; is covered in this blog.
// Merge with monthly financial data
# delimit ;
use fin_variables21jan2023.dta, clear;
merge m:m period using FEDFUNDS.dta,
keep(1 3) nogen ;
keep if imfcode==111 ;
keep if period>=tm(2004m1) ;
set scheme stcolor_alt ;
tsline shadow_rate FEDFUNDS, legend(pos(6))
tlabel(, format(%tmCCYY)) ;
graph rename cycles, replace;
display tm(2001m1) ;
display tm(2024m1) ;
#delimit cr
In the last part of the code, I will leverage my blog on NBER recessions to shade tightening cycles. Do not forget to summarize the series with the largest range to scale up the bars. In this example, 6 and minus 4 are the maximum and the minimum of the Shadow Rate, respectively.
// Generate tightening bars
# delimit ;
cap drop REC ;
generate REC = 0 ;
replace REC = 1
if period>=tm(2004m6) & period<=tm(2007m6) |
period>=tm(2014m6) & period<=tm(2018m12) |
period>=tm(2022m2) & period<=tm(2023m11) ;
#delimit cr
summarize shadow_rate if period>=tm(2004m1)
gen REC13=REC*6
// Scale up the bars
label variable REC "US Monetary Tightenings"
label variable REC13 "US Monetary Tightenings"
label var period "Date"
generate Tightening = 6 if REC13 == 6
// 6 is the max of the y-axis
replace Tightening = -4 if REC13 == 0
// -4 is the min of the y-axis
Now, we can draw the final graph. The only thing that may be a bit cumbersome is finding the best emplacement for the text label associated to each cycle. You have to use the text option of the twoway command. For example, text(-3 551 “{bf:Before GFC}) will place the text at the y = -3 and x = 551. 551 corresponds to the 551 months after the start of the time for Stata, see this blog for more details.
// Draw the final graph
# delimit ;
twoway
(bar Tightening period, color(gs14%50)
lstyle(none) barwidth(1) bargap(0)
base(-4) xsize(8) ytitle(Rates in percent)
title("{bf:FEDs' Easing versus
Tightening Cycles}"))
(tsline shadow_rate FEDFUNDS, lcolor(red blue)
xlabel(542 602 666 726 776)
tlabel(542 602 666 726 776,
format(%tmCCYY))), ysc(r(-4 6))
yline(0) legend(pos(6) col(3) size(normal))
text(-3 551 "{bf:Before GFC}"
"{it:Jun 2004 - Jun 2007}",
size(small))
text(2 615 "{bf:GFC}"
"{it:Jul 2007 - May 2014}",
size(small))
text(5 680 "{bf:Taper Tantrum}"
"{it:Jun 2014 - Dec 2018}",
size(small))
text(3.5 726 "{bf:COVID-19 cycle}"
"{it:Jan 2019 - Jan 2022}",
size(small))
text(-3 754 "{bf:Post COVID-19}"
"{it:Feb 2022 - Sep 2023}",
size(small))
graphregion(margin(l+2 r+2))
note(Source: ADB Working Paper 735.);
Now, you can rename the graph and export it in the desired subfolder. The ‘figures’ subfolder in this example:
// Export the graph in two different formats
# delimit ;
graph rename monetary_cycles, replace ;
graph export figures\monetary_cycles.png, as(png)
width(4000) replace ;
graph export figures\monetary_cycles.pdf, as(pdf)
replace ;
#delimit cr
**# **** End of program ****
The full code is presented below for replication purposes. The file fin_variables21jan2023.dta is not provided, but US Shadow Rates are available on Jing Cynthia Wu’s website. You may have to change the merge (to merge 1:1) if you only use times series data to merge with the Fed funds rates, instead of panel data in this example.
**# **** Figure 1 in the paper ****
// FEDFUNDS data from FRED
*set fredkey 'yourkey', permanently
import fred FEDFUNDS, clear
generate datem = mofd(daten)
tsset datem, monthly
rename datem period
drop datestr daten
order period FEDFUNDS
save FEDFUNDS.dta, replace
// Merge with monthly financial data
# delimit ;
use fin_variables21jan2023.dta, clear;
merge m:m period using FEDFUNDS.dta,
keep(1 3) nogen ;
keep if imfcode==111 ;
keep if period>=tm(2004m1) ;
set scheme stcolor_alt ;
tsline shadow_rate FEDFUNDS, legend(pos(6))
tlabel(, format(%tmCCYY)) ;
graph rename cycles, replace;
display tm(2001m1) ;
display tm(2024m1) ;
#delimit cr
// Generate tightening bars
# delimit ;
cap drop REC ;
generate REC = 0 ;
replace REC = 1
if period>=tm(2004m6) & period<=tm(2007m6) |
period>=tm(2014m6) & period<=tm(2018m12) |
period>=tm(2022m2) & period<=tm(2023m11) ;
#delimit cr
gen REC13=REC*6
// Scale up the bars
label variable REC "US Monetary Tightenings"
label variable REC13 "US Monetary Tightenings"
label var period "Date"
summarize shadow_rate if period>=tm(2004m1)
generate Tightening = 6 if REC13 == 6
// 6 is the max of the y-axis
replace Tightening = -4 if REC13 == 0
// Draw the final graph
# delimit ;
twoway
(bar Tightening period, color(gs14%50)
lstyle(none) barwidth(1) bargap(0)
base(-4) xsize(8) ytitle(Rates in percent)
title("{bf:FEDs' Easing versus
Tightening Cycles}"))
(tsline shadow_rate FEDFUNDS, lcolor(red blue)
xlabel(542 602 666 726 776)
tlabel(542 602 666 726 776,
format(%tmCCYY))), ysc(r(-4 6))
yline(0) legend(pos(6) col(3) size(normal))
text(-3 551 "{bf:Before GFC}"
"{it:Jun 2004 - Jun 2007}",
size(small))
text(2 615 "{bf:GFC}"
"{it:Jul 2007 - May 2014}",
size(small))
text(5 680 "{bf:Taper Tantrum}"
"{it:Jun 2014 - Dec 2018}",
size(small))
text(3.5 726 "{bf:COVID-19 cycle}"
"{it:Jan 2019 - Jan 2022}",
size(small))
text(-3 754 "{bf:Post COVID-19}"
"{it:Feb 2022 - Sep 2023}",
size(small))
graphregion(margin(l+2 r+2))
note(Source: ADB Working Paper 735.);
#delimit cr
// Export the graph in two different formats
# delimit ;
graph rename monetary_cycles, replace ;
graph export figures\monetary_cycles.png, as(png)
width(4000) replace ;
graph export figures\monetary_cycles.pdf, as(pdf)
replace ;
#delimit cr
**# **** End of program ****
1 Comment
[…] markets during US monetary cycles (also available as a NBER WP). This project has been covered on a previous blog of mine. In this ongoing project, we focus on the impact of the ECB’s monetary cycles on the […]