Skip to content

Commit 524de15

Browse files
jstacclaudemmcky
authored
Update business cycle data to latest available (#364) (#770)
* Update business cycle data to latest available (#364) FRED series had hardcoded end dates of 2022-12-31, capping the unemployment, NBER recession, consumer sentiment/CPI and industrial output series. Switch these to datetime.now() so the lecture always pulls the most recent data, matching the auto-updating World Bank series. Also pin the most recent year as an explicit x-axis tick in plot_series and plot_comparison, so the extended GDP series read as intentional rather than trailing off past the last labelled tick. Update prose that referenced fixed end years (2022) to "the present". Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * Centralize data cutoff and make narrative evergreen Address narrative-drift risk from dynamic data dates: - Define the data cutoff once (end_date) with a documented one-line switch to pin it for reproducible builds, instead of repeating datetime.now() across four FRED cells. - Rename the 1942 historical cutoff to hist_end_date so it no longer clobbers the shared end_date in the unemployment cell. - Reword the post-pandemic labour-market sentence to be anchored to the 2020 shock rather than to the moving right edge of the chart. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * Drop the pinned final-year x-axis tick The added final-year tick crowded the existing 2020 ("Covid-19") tick and looked worse than the gap it was meant to address. Revert to matplotlib's default x-axis ticks in plot_series and plot_comparison. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: Matt McKay <mmcky@users.noreply.github.com>
1 parent e7e7571 commit 524de15

1 file changed

Lines changed: 20 additions & 15 deletions

File tree

lectures/business_cycle.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ cycler = plt.cycler(linestyle=['-', '-.', '--', ':'],
5353
plt.rc('axes', prop_cycle=cycler)
5454
```
5555

56+
We pull all time series through to the most recent available data.
57+
58+
```{code-cell} ipython3
59+
# The cutoff date for the data we fetch below.
60+
# To freeze the data for a reproducible build, replace this with a
61+
# fixed date such as datetime.datetime(2024, 12, 31).
62+
end_date = datetime.datetime.now()
63+
```
64+
5665

5766
## Data acquisition
5867

@@ -316,27 +325,26 @@ economy recessions in the 1970s and 1990s.
316325

317326
Another important measure of business cycles is the unemployment rate.
318327

319-
We study unemployment using rate data from FRED spanning from [1929-1942](https://fred.stlouisfed.org/series/M0892AUSM156SNBR) to [1948-2022](https://fred.stlouisfed.org/series/UNRATE), combined unemployment rate data over 1942-1948 estimated by the [Census Bureau](https://www.census.gov/library/publications/1975/compendia/hist_stats_colonial-1970.html).
328+
We study unemployment using rate data from FRED spanning from [1929-1942](https://fred.stlouisfed.org/series/M0892AUSM156SNBR) to [1948 onwards](https://fred.stlouisfed.org/series/UNRATE), combined unemployment rate data over 1942-1948 estimated by the [Census Bureau](https://www.census.gov/library/publications/1975/compendia/hist_stats_colonial-1970.html).
320329

321330
```{code-cell} ipython3
322331
:tags: [hide-input]
323332
324333
start_date = datetime.datetime(1929, 1, 1)
325-
end_date = datetime.datetime(1942, 6, 1)
334+
hist_end_date = datetime.datetime(1942, 6, 1)
326335
327336
unrate_history = web.DataReader('M0892AUSM156SNBR',
328-
'fred', start_date,end_date)
337+
'fred', start_date, hist_end_date)
329338
unrate_history.rename(columns={'M0892AUSM156SNBR': 'UNRATE'},
330339
inplace=True)
331340
332341
start_date = datetime.datetime(1948, 1, 1)
333-
end_date = datetime.datetime(2022, 12, 31)
334342
335343
unrate = web.DataReader('UNRATE', 'fred',
336344
start_date, end_date)
337345
```
338346

339-
Let's plot the unemployment rate in the US from 1929 to 2022 with recessions
347+
Let's plot the unemployment rate in the US from 1929 to the present with recessions
340348
defined by the NBER.
341349

342350
```{code-cell} ipython3
@@ -359,7 +367,6 @@ unrate_census.set_index('DATE', inplace=True)
359367
360368
# Obtain the NBER-defined recession periods
361369
start_date = datetime.datetime(1929, 1, 1)
362-
end_date = datetime.datetime(2022, 12, 31)
363370
364371
nber = web.DataReader('USREC', 'fred', start_date, end_date)
365372
@@ -398,10 +405,10 @@ The plot shows that
398405
* cycles are, in general, asymmetric: sharp rises in unemployment are followed
399406
by slow recoveries.
400407

401-
It also shows us how unique labor market conditions were in the US during the
402-
post-pandemic recovery.
408+
It also shows how unusual the US labor market was in the recovery from the 2020
409+
pandemic shock.
403410

404-
The labor market recovered at an unprecedented rate after the shock in 2020-2021.
411+
Unemployment spiked sharply in 2020 and then fell back at an unprecedented rate.
405412

406413

407414
(synchronization)=
@@ -616,7 +623,7 @@ of Michigan.
616623
Here we plot the University of Michigan Consumer Sentiment Index and
617624
year-on-year
618625
[core consumer price index](https://fred.stlouisfed.org/series/CPILFESL)
619-
(CPI) change from 1978-2022 in the US.
626+
(CPI) change from 1978 to the present in the US.
620627

621628
```{code-cell} ipython3
622629
---
@@ -628,11 +635,10 @@ tags: [hide-input]
628635
---
629636
630637
start_date = datetime.datetime(1978, 1, 1)
631-
end_date = datetime.datetime(2022, 12, 31)
632638
633639
# Limit the plot to a specific range
634640
start_date_graph = datetime.datetime(1977, 1, 1)
635-
end_date_graph = datetime.datetime(2023, 12, 31)
641+
end_date_graph = end_date + datetime.timedelta(days=365)
636642
637643
nber = web.DataReader('USREC', 'fred', start_date, end_date)
638644
consumer_confidence = web.DataReader('UMCSENT', 'fred',
@@ -698,7 +704,7 @@ However, it is not a leading indicator, as the peak of contraction in production
698704
is delayed relative to consumer confidence and inflation.
699705

700706
We plot the real industrial output change from the previous year
701-
from 1919 to 2022 in the US to show this trend.
707+
from 1919 to the present in the US to show this trend.
702708

703709
```{code-cell} ipython3
704710
---
@@ -710,7 +716,6 @@ tags: [hide-input]
710716
---
711717
712718
start_date = datetime.datetime(1919, 1, 1)
713-
end_date = datetime.datetime(2022, 12, 31)
714719
715720
nber = web.DataReader('USREC', 'fred',
716721
start_date, end_date)
@@ -746,7 +751,7 @@ activity and gloomy expectations for the future.
746751
One example is domestic credit to the private sector by banks in the UK.
747752

748753
The following graph shows the domestic credit to the private sector as a
749-
percentage of GDP by banks from 1970 to 2022 in the UK.
754+
percentage of GDP by banks from 1970 to the present in the UK.
750755

751756
```{code-cell} ipython3
752757
---

0 commit comments

Comments
 (0)