Skip to content
3 min read · Tags: plotting api window-functions datetime

BW #115: Sahm rule

Get better at: API use, window functions, dates and times, and plotting.

BW #115: Sahm rule

At the start of this year, the US was poised for economic growth, especially compared with other Western nations. The Economist said that the US was "the envy of the world." The International Monetary Fund (IMF) predicted 2.7 percent growth in 2025.

But Donald Trump's tariffs, along with the lack of clarity and consistency in applying and communicating them, convinced the IMF to change their forecast. They have lowered expectations to 1.8 percent growth, along with a 40 percent chance of a recession (https://www.bbc.com/news/live/c4g2l654dket?post=asset%3Ac8a833cf-e224-4d0f-8374-4f62c6d44376#post).

Combine this with the recent plunge in consumer confidence (covered in BW 107, https://www.bambooweekly.com/bw-107-consumer-confidence/), across-the-board declines in stock-market indexes, higher bond yields (indicating greater perceived risk), and it's no surprise that people are openly talking about whether the US is already in a recession -- not whether one is likely to happen later this year.

Is the United States in a recession? Truth be told, we don't know, and we won't know for a while. In the US, it's generally accepted that the National Bureau of Economic Research (NBER, https://www.nber.org/) marks the start and end of a recession. However, it can only do so after the recession has started, and often months after it has started.

Economist Claudia Sahm (https://en.wikipedia.org/wiki/Claudia_Sahm) is famous for creating the "Sahm rule" (https://en.wikipedia.org/wiki/Sahm_rule), providing a real-time indication of whether a recession has started. As Sahm herself writes, "When the three-month moving average of the national unemployment rate is 0.5 percentage point or more above its low over the prior twelve months, we are in the early months of recession." (She also wrote, "I created a monster," saying that it was meant to be a policy tool, not a predictor of recessions. And yet, that's why everyone is talking about it.)

Paul Krugman interviewed Sahm earlier this month; if you find this stuff interesting, I recommend watching it, or reading the transcript: https://paulkrugman.substack.com/p/an-interview-with-claudia-sahm

This week, we'll look at recent US economic data to determine whether a recession has begun, at least according to the Sahm rule. Along the way, we'll get to explore some interesting Pandas functionality, including window functions, that are used in these calculations.

Data and five questions

This week, we'll be performing calculations using the Sahm rule. We'll get our data from FRED (https://fred.stlouisfed.org/), the online economics portal run by the St. Louis Federal Reserve. It's totally possible to download values directly from FRED, and then import that data into Pandas. This week, however, we'll retrieve the unemployment data using the fredapi package on GitHub (https://github.com/mortada/fredapi), which does a great deal of the hard work for us.

In order to use fredapi, you'll need to get a FRED API key, available for free from https://fredaccount.stlouisfed.org/apikey .

This week's learning goals include working with APIs, window functions, dates and times, and plotting.

Normally, paid subscribers can download the data from the bottom of this newsletter. I won't be doing that this week, though, in order to encourage you to use the API.

I'll be back tomorrow with my detailed solution, as well as (for paid subscribers) a downloadable notebook in which I solve these problems, as well as one-click access to my notebook and the data in Google Colab.

Meanwhile, here are my five tasks and questions for you: