BW #93: Anti-politics
[Like many others, I've been getting active on BlueSky, posting threads on Python/Pandas topics. Follow me there, at https://bsky.app/@lernerpython.com! I've even created a starter pack with lots of Python authors, lecturers, and teachers, at https://go.bsky.app/M5WjB4s . See you there!
When you vote, are you choosing a candidate you like? Or are you voting against a candidate you fear or cannot stand? The Economist recently published a long essay, "The anti-politics eating the West," in which they examined data from a large number of elections in democratic countries over the last number of decades. (If you have an Economist subscription, then you can read the article at https://www.economist.com/interactive/essay/2024/10/31/when-politics-is-about-hating-the-other-side-democracy-suffers .) The article described this as "anti-politics" and "negative partisanship," and warned that such feelings are leading people to distrust government in general, and democratically elected governments in particular.
But this wasn't just a long-winded political analysis. Rather, the article was based on some serious research and data analysis, done in no small part by Diego Garzia and Frederico Ferreira da Silva, both of the University of Lausanne in Switzerland. They compared a huge number of elections across many years and countries to understand what leads to more (and less) partisanship.
As soon as I saw a reference in the article to a GitHub repository with all of their data, I became quite excited, and decided to use it fo this week's edition of Bamboo Weekly. However, there's a reason why it took a team at the Economist, along with a number of professors and researchers, to prepare this report: There's a lot of data, and making sense of it isn't easy. Just getting the data files into a form that their programs (written in R) could process took quite a long time.
And so, this week, we'll look at a small subset of the data used in this article, looking for a growing partisan bias in Western democracies.
Data and six questions
This week's data is all collected for us in the GitHub repo for the article:
https://github.com/TheEconomist/anti-politics
I succeeded in installing the R programs and data that they requested, but it wasn't easy, fast, or smooth. So we'll concentrate instead on two of the data files in the repo:
garzia-and-ferreira-da-silva/eco_cses.dta
, a Stata data file, andmilitary-spending/the_economist_military_spending.csv
, a CSV file prepared by the Economist.
Both of these files, as well as the rest of the data they used, is in the source-data
directory of the GitHub repository.
This week's learning goals include filtering, indexes and multi-indexes, grouping and pivot tables, plotting (including customizing plots), and interpolation.
I'll be back tomorrow with my solutions, including the Jupyter notebook I used to solve these six problems:
- Read the Stata data from Garzia and Ferrira da Silva (
eco_cses.dta
) into a data frame. TheCOUNTRY
column should be turned into the index. - Create a data frame in which years form the rows and there's a multi-index on the columns, with the top level being the
INPARTY
andOUTPARTY
measures, and the inner level being the country names.