BW #17: Debt ceiling
The amount of debt the US can issue is approaching its limit, known as the "debt ceiling." What does the debt look like, and who holds it? Let's find out, using Pandas and ChatGPT!
The US debt ceiling has been in financial headlines for a few months — but this week, it finally started to get real, as government officials (including US treasury secretary Janet Yellen) warned that if the debt ceiling isn’t raised, then the US might have to default on its obligations.
Wait, what? Is she saying that the US will run out of money?
Yes, pretty much. But wait, it’s much worse than that.
‘One of the main things that a government has to do is pass a budget. That’s a law which says that well spend a certain amount on schools, another amount on transportation, another amount on the military, another amount on salaries, and so forth. The budget is a massive document, and it’s typically the result of a ton of horse-trading and discussion.
What happens if a government cannot pay its bills? It borrows money, of course. But whereas you and I would go to the bank to borrow some money, governments typically issue bonds. If I buy a 1-year US treasury bond, then I’m basically lending money to the US government for 1 year. I expect to get my money back in a year, plus some interest.
People buy US treasuries because they're considered safe. If you have to park your money somewhere, you might as well buy some treasuries, which will pay you something, which is better than nothing.
It used to be, many decades ago, that every time the US wanted to issue bonds, it had to pass a new law allowing for it. At a certain point, Congress passed a law allowing the government to issue bonds up to a particular ceiling. In other words, the "debt ceiling."
What happens if the US hits the debt ceiling? Every news report I've heard and read has called it "very bad." And that’s quite an understatement; not only would many Americans fail to get their Social Security checks, medical payments, and military salaries, but all sorts of government payments would just stop.
Those stopped payments would include payments due to people who bought US treasuries. Which includes lots of individuals, companies, and foreign governments. When a country defaults on its bonds (i.e., doesn’t pay them), it’s … not good.
If everyone agrees that hitting the debt limit would be catastrophically bad, then why doesn't Congress get rid of it? Or just raise it to some crazy-high amount? That is a political question, and right now, the Republican party is running the House of Representatives. And they see the debt ceiling as a way to extract concessions from the Democrats, including from Joe Biden. In their ideal world, Republicans would reverse all of the budget laws that Democrats passed in the last few years. In reality, it's currently looking like a game of chicken, with the US economy at risk, and the world economy dragged along with it.
Marketplace, a public radio show about business and economics, dedicated its entire Monday show to discussing the debt limit here: https://www.marketplace.org/shows/marketplace/whats-really-at-the-heart-of-the-debt-limit-debate/. Kai Ryssdal, Marketplace’s anchor, tweeted a link to this story, describing what would happen if the US were to default: https://apnews.com/article/debt-limit-congress-world-economy-recession-biden-52df635e9b89f4b1677176fc8d59eff0
I should add that there are a few suggested ways to avoid the debt-ceiling crisis without negotiating with the Republicans. One of them is to simply declare that the US can’t default, and thus the entire debt ceiling is unconstitutional. Another is (I kid you not) to mint a coin, entirely out of platinum, worth several trillion (yes, trillion) dollars. With that coin in hand, the government would have money, and the problem would be solved. You can read more about that here: https://en.wikipedia.org/wiki/Trillion-dollar_coin. (It’s also mentioned in the Marketplace segment I referenced above.)
I thus decided that this week, we’ll look at data having to do with the US federal debt and the debt ceiling. I want to see what we can learn about federal debt, including what other countries own US treasuries, and how much the US government is paying to service its debt.
Here’s the catch, though: I’m going to pose some questions, and I want you to answer those questions using Pandas. But I don’t want you to write any Pandas code directly. Rather, I want you to use ChatGPT to do the analysis for you.
Confused? Let me explain: ChatGPT has been around for about six months, and for much of that time, it was using a large-language model (LLM) known as GPT-3.5. That model wowed a lot of people (including me -- see https://lerner.co.il/2022/12/11/my-week-with-chatgpt/), for a whole lot of reasons. We kept hearing that we would be wowed even more by the next model, known as GPT-4. And yes, it’s much better than GPT-3.5. But the real magic, as far as I’m concerned, is that this model supports plugins. This means that a company can make it possible for ChatGPT to access and control its systems via an API.
One of those companies is Noteable (https://noteable.io), which has developed what I’ve been calling Jupyter on steroids. (I first encountered the company at PyCon US last month, and I had a conversation with one of their people a few days ago, but I’m otherwise not affiliated with the company. That said, I'm super duper impressed with what they've done, and may well start to use their products in my training.) Use of Noteable is free for individuals, and while it’s restricted to a virtual machine with limited memory and processing power, it’s more than good enough for many small tasks, including what we'll be doing this week.
So yes, that means that if you want, you can now ask ChatGPT’s GPT-4 model to perform data analysis operations. It'll do that analysis within one of Noteable’s notebooks. You can then inspect the code, analyze it, modify it, and share it with others.
The one catch is that GPT-4 and plugins are only available via ChatGPT+, the paid ($20/month) subscription product that OpenAI offers. I apologize to the many Bamboo Weekly subscribers who can't or won't pay for this service; for that reason, I'm going to keep this week's solutions open to the public. I'll also create a YouTube video in which I go through how to solve it.
If you are willing and able to pay for ChatGPT+, and are willing to sign up for Noteable's free tier, then I'd like you to give it a shot. That is, I'd like you to answer this week's questions by translating them into language ChatGPT+ will understand -- and then I'd like you to inspect the Python and Pandas code that is created, debugging and critiquing it as necessary.
You can, of course, also answer the questions directly yourself, writing Python and Pandas code. But that seems so old school and quaint, no?
Data and questions
This week’s data will come from three different sources:
The total amount of federal debt, as tracked via the amazing FRED site out of the St. Louis Federal Reserve: https://fred.stlouisfed.org/series/GFDEBTN
Interest payments that the federal government is paying on the debts, also from FRED: https://fred.stlouisfed.org/series/A091RC1Q027SBEA
Finally, a file produced regularly by the US Treasury Department, indicating how much US debt is owned by a number of different countries: https://ticdata.treasury.gov/Publish/mfh.txt
I’d like you to go through these files, load them into data frames, and then produce a number of plots that help to explain the current debt situation from a variety of angles.
But again, I don’t want you to write your Pandas code directly! Wherever possible, use ChatGPT and the Noteable plugin to do the work for you.
I’ll be back tomorrow with my solution, both in text and in a YouTube video that I’m producing showing my solution, and how I used ChatGPT to answer my questions.
Create a Jupyter notebook. In that notebook, create one Pandas data frame with the total amount of federal debt at https://fred.stlouisfed.org/series/GFDEBTN.
Use Seaborn to plot the total federal debt over the last three decades. The x axis should represent time, and the y axis should represent the amount of debt. Analyze the plot in Markdown, just below the plot.
In the same notebook, download https://fred.stlouisfed.org/series/A091RC1Q027SBEA (interest payments on the Federal debt) into a separate data frame.
Use Seaborn to plot interest payments over the last three decades. The x axis should represent time, and the y axis should represent the interest payments. Analyze the plot in Markdown, just below the plot.
Use Seaborn to create a scatter plot, comparing the federal debt and the interest payments on the debt in the last three decades. Include a regression line in this plot. What correlations do you see? Describe your findings in Markdown, just below the plot.
Download data from https://ticdata.treasury.gov/Publish/mfh.txt. Before parsing the file, remove everything before the word "Japan". Also remove the line that starts with "Grand Total", and everything that follows it. Create a data frame from the text that remains. The data frame does *not* have any headers; interpret the first line as data. Each line consists of a country name and floating-point numbers. The fields are separated by two or more space characters. The first field on each line, the country name, should be made the index. The remaining values will all be floating-point numbers. The data frame's column names should be a combination of month name and year, starting with "Jan-2023" and going down, one month at a time, until reaching the final column.
Using Seaborn, create a pie chart showing what proportion of debt was owned by each country in Jan 2023. Do this for the top 15 countries; all others should be lumped into a single pie segment labeled "others".
Using Seaborn, create an area plot showing the holdings of the top 5 countries holding treasury securities over time. Ignore "All Other" when choosing the top 5. Analyze the plot in Markdown, just below the plot. Turn it around, so that January 2022 is on the left, and January 2023 is on the right.
Create a pie chart showing what proportion of debt was owned by each continent, rather than each country. That is, we should have one pie slice for Asia, another for Europe, another for Africa, etc. Any countries that cannot be classified into a continent can remain named.
To the best of your ability, classify each of the countries as a democracy or a dictatorship. Create a pie chart showing what proportion of debt was owned by each type of government. If you can think of additional classifications for countries, feel free to use those. Any countries that cannot be classified into a governmental system can remain named.
The learning goals for this week include Pandas, Seaborn, working with fixed-width files, joins, and readying ourselves for enslavement by our robot overloads.
I’ll be back tomorrow with my solution and thoughts. Meanwhile, post yours in the comments!
At first pass, ChatGPT was able to figure out the correct API to use in order to pull the data, amazing!