Skip to content

Commit

Permalink
Merge branch 'graph-work' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
thomassargent30 committed Jul 26, 2023
2 parents 294121a + d1523ad commit 1e8f135
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 13 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
136 changes: 123 additions & 13 deletions lectures/long_run_growth.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,52 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.14.4
jupytext_version: 1.14.5
kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
---

+++ {"user_expressions": []}

# Economic Growth Evidence

## Overview

Adam Tooze's account of the geopolitical precedents and antecedents of World War I includes a comparison of how Gross National Products of European Great Powers had evolved during the 70 years preceding 1914 (see chapter 1 of {cite}`Tooze_2014`).
In this lecture we use Python, Pandas, and Matplotlib to download, organize, and visualize historical data on GDP growth.

We construct a version of Tooze's graph later in this lecture.
In addition to learning how to deploy these tools more generally, we'll use them to describe facts about economic growth experiences across many countries over several centuries.

(An impatient reader can jump ahead and look at figure {numref}`gdp1`.)
Such "growth facts" are interesting for a variety of reasons.

Looking at his graph and how it set the geopolitical stage for "the American (20th) century" naturally
Explaining growth facts is a principal purpose of both "development economics" and "economic history".

And growth facts are important inputs into historians' studies of geopolitical forces and dynamics.


Thus, Adam Tooze's account of the geopolitical precedents and antecedents of World War I begins by describing how Gross National Products of European Great Powers had evolved during the 70 years preceding 1914 (see chapter 1 of {cite}`Tooze_2014`).

Using the very same data that Tooze used to construct his figure, here is our version of his chapter 1 figure.


```{figure} _static/lecture_specific/long_run_growth/tooze_ch1_graph.png
:width: 75%
```

(This is just a copy of our figure {numref}`gdp1`. We desribe how we constructed it later in this lecture.)

Chapter 1 of {cite}`Tooze_2014` used his graph to show how US GDP started the 19th century way behind the GDP of the British Empire.

By the end of the nineteenth century, US GDP had caught up with GDP of the British Empire, and how during the first half of the 20th century,
US GDP surpassed that of the British Empire.

For Adam Tooze, that fact was a key geopolitical underpinning for the "American century".

Looking at this graph and how it set the geopolitical stage for "the American (20th) century" naturally
tempts one to want a counterpart to his graph for 2014 or later.

(An impatient reader might now want to jump ahead and look at figure {numref}`gdp2`.)
(An impatient reader seeking a hint at the answer might now want to jump ahead and look at figure {numref}`gdp2`.)

As we'll see, reasoning by analogy, this graph perhaps set the stage for an "XXX (21st) century", where you are free to fill in your guess for country XXX.

Expand Down Expand Up @@ -53,6 +77,8 @@ from collections import namedtuple
from matplotlib.lines import Line2D
```

+++ {"user_expressions": []}

## Setting up

A project initiated by [Angus Maddison](https://en.wikipedia.org/wiki/Angus_Maddison) has collected many historical time series related to economic growth,
Expand All @@ -69,6 +95,8 @@ data = pd.read_excel("datasets/mpd2020.xlsx", sheet_name='Full data')
data
```

+++ {"user_expressions": []}

We can see that this dataset contains GDP per capita (gdppc) and population (pop) for many countries and years.

Let's look at how many and which countries are available in this dataset
Expand All @@ -77,6 +105,7 @@ Let's look at how many and which countries are available in this dataset
len(data.country.unique())
```

+++ {"user_expressions": []}

We can now explore some of the 169 countries that are available.

Expand All @@ -92,6 +121,7 @@ cntry_years = pd.DataFrame(cntry_years, columns=['country', 'Min Year', 'Max Yea
cntry_years
```

+++ {"user_expressions": []}

Let's now reshape the original data into some convenient variables to enable quicker access to countries time series data.

Expand All @@ -101,6 +131,7 @@ We can build a useful mapping between country codes and country names in this da
code_to_name = data[['countrycode','country']].drop_duplicates().reset_index(drop=True).set_index(['countrycode'])
```

+++ {"user_expressions": []}

Then we can quickly focus on GDP per capita (gdp)

Expand All @@ -117,19 +148,24 @@ gdppc = gdppc.unstack('countrycode')
gdppc
```

+++ {"user_expressions": []}

We create a color mapping between country codes and colors for consistency

```{code-cell} ipython3
:tags: [hide-input]
country_names = data['countrycode']
# Generate a colormap with the number of colors matching the number of countries
colors = cm.Dark2(np.linspace(0, 0.8, len(country_names)))
colors = cm.tab20(np.linspace(0, 0.95, len(country_names)))
# Create a dictionary to map each country to its corresponding color
color_mapping = {country: color for country, color in zip(country_names, colors)}
```

+++ {"user_expressions": []}

## GPD plots

Looking at the United Kingdom we can first confirm we are using the correct country code
Expand All @@ -152,6 +188,7 @@ _ = gdppc[cntry].plot(
color=color_mapping['GBR'])
```

+++ {"user_expressions": []}

:::{note}
[International Dollars](https://en.wikipedia.org/wiki/International_dollar) are a hypothetical unit of currency that has the same purchasing power parity that the U.S. Dollar has in the United States at any given time. They are also known as Geary–Khamis dollars (GK Dollars).
Expand Down Expand Up @@ -184,6 +221,7 @@ ax.set_xlabel('Year')
plt.show()
```

+++ {"user_expressions": []}

We can now put this into a function to generate plots for a list of countries

Expand Down Expand Up @@ -214,13 +252,14 @@ def draw_interp_plots(series, ylabel, xlabel, color_mapping, code_to_name, lw, l
ax.set_yscale('log')
# Draw the legend outside the plot
ax.legend(loc='lower center', ncol=5, bbox_to_anchor=[0.5, -0.25])
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5), frameon=False)
ax.set_ylabel(ylabel)
ax.set_xlabel(xlabel)
return ax
```

+++ {"user_expressions": []}

As you can see from this chart, economic growth started in earnest in the 18th century and continued for the next two hundred years.

Expand Down Expand Up @@ -294,6 +333,7 @@ draw_events(events, ax)
plt.show()
```

+++ {"user_expressions": []}

The preceding graph of per capita GDP strikingly reveals how the spread of the industrial revolution has over time gradually lifted the living standards of substantial
groups of people
Expand Down Expand Up @@ -364,6 +404,8 @@ draw_events(events, ax)
plt.show()
```

+++ {"user_expressions": []}

We can also look at the United States (USA) and United Kingdom (GBR) in more detail

In the following graph, please watch for
Expand Down Expand Up @@ -423,6 +465,7 @@ draw_events(events, ax)
plt.show()
```

+++ {"user_expressions": []}

## The industrialized world

Expand All @@ -437,6 +480,8 @@ data['gdp'] = data['gdppc'] * data['pop']
gdp = data['gdp'].unstack('countrycode')
```

+++ {"user_expressions": []}

### Early industrialization (1820 to 1940)

We first visualize the trend of China, the Former Soviet Union, Japan, the UK and the US.
Expand All @@ -457,17 +502,73 @@ mystnb:
fig, ax = plt.subplots(dpi=300)
ax = fig.gca()
cntry = ['CHN', 'SUN', 'JPN', 'GBR', 'USA']
start_year, end_year = (1820, 1940)
start_year, end_year = (1820, 1945)
ax = draw_interp_plots(gdp[cntry].loc[start_year:end_year],
'International $\'s','Year',
color_mapping, code_to_name, 2, False, ax)
```

+++ {"user_expressions": []}

### The modern era (1950 to 2020)
## Constructing a plot similar to Tooze's
In this section we describe how we have constructed a version of the striking figure from chapter 1 of {cite}`Tooze_2014` that we discussed at the start of this lecture.

Let's first define a collection of countries that consist of the British Empire (BEM) so we can replicate that series in Tooze's chart.

```{code-cell} ipython3
BEM = ['GBR', 'IND', 'AUS', 'NZL', 'CAN', 'ZAF']
gdp['BEM'] = gdp[BEM].loc[start_year-1:end_year].interpolate(method='index').sum(axis=1) # Interpolate incomplete time-series
```

+++ {"user_expressions": []}

Let's take a look at the aggregation that represents the British Empire.

```{code-cell} ipython3
gdp['BEM'].plot() # The first year is np.nan due to interpolation
```

The following graph displays how quickly China has grown, especially since the late 1970s.
```{code-cell} ipython3
code_to_name
```

+++ {"user_expressions": []}

Now let's assemble our series and get ready to plot them.

```{code-cell} ipython3
# Define colour mapping and name for BEM
color_mapping['BEM'] = color_mapping['GBR'] # Set the color to be the same as Great Britain
# Add British Empire to code_to_name
bem = pd.DataFrame(["British Empire"], index=["BEM"], columns=['country'])
bem.index.name = 'countrycode'
code_to_name = pd.concat([code_to_name, bem])
```

```{code-cell} ipython3
fig, ax = plt.subplots(dpi=300)
ax = fig.gca()
cntry = ['DEU', 'USA', 'SUN', 'BEM', 'FRA', 'JPN']
start_year, end_year = (1821, 1945)
ax = draw_interp_plots(gdp[cntry].loc[start_year:end_year],
'Real GDP in 2011 $\'s','Year',
color_mapping, code_to_name, 2, False, ax)
plt.savefig("./_static/lecture_specific/long_run_growth/tooze_ch1_graph.png", dpi=300, bbox_inches='tight')
plt.show()
```

+++ {"user_expressions": []}

At the start of this lecture, we noted how US GDP came from "nowhere" at the start of the 19th century to rival and then overtake the GDP of the British Empire
by the end of the 19th century, setting the geopolitical stage for the "American (twentieth) century".

Let's move forward in time and start roughly where Tooze's graph stopped after World War II.

In the spirit of Tooze's chapter 1 analysis, doing this will provide some information about geopolitical realities today.

### The modern era (1950 to 2020)

The following graph displays how quickly China has grown, especially since the late 1970s.

```{code-cell} ipython3
---
Expand All @@ -484,6 +585,9 @@ ax = draw_interp_plots(gdp[cntry].loc[start_year:end_year],
'International $\'s','Year',
color_mapping, code_to_name, 2, False, ax)
```

+++ {"user_expressions": []}

It is tempting to compare this graph with figure {numref}`gdp1` that showed the US overtaking the UK near the start of the "American Century", a version of the graph featured in chapter 1 of {cite}`Tooze_2014`.

## Regional analysis
Expand All @@ -497,19 +601,25 @@ data = pd.read_excel("datasets/mpd2020.xlsx", sheet_name='Regional data', header
data.columns = data.columns.droplevel(level=2)
```

+++ {"user_expressions": []}

We can save the raw data in a more convenient format to build a single table of regional GDP per capita

```{code-cell} ipython3
regionalgdppc = data['gdppc_2011'].copy()
regionalgdppc.index = pd.to_datetime(regionalgdppc.index, format='%Y')
```

+++ {"user_expressions": []}

Let's interpolate based on time to fill in any gaps in the dataset for the purpose of plotting

```{code-cell} ipython3
regionalgdppc.interpolate(method='time', inplace=True)
```

+++ {"user_expressions": []}

and record a dataset of world GDP per capita

```{code-cell} ipython3
Expand All @@ -523,7 +633,6 @@ mystnb:
caption: World GDP per capita
name: world_gdppc
---
fig = plt.figure(dpi=300)
ax = fig.gca()
ax = worldgdppc.plot(
Expand All @@ -533,6 +642,8 @@ ax = worldgdppc.plot(
)
```

+++ {"user_expressions": []}

Looking more closely, let's compare the time series for `Western Offshoots` and `Sub-Saharan Africa` and more broadly at a number of different regions around the world.

Again we see the divergence of the West from the rest of the world after the industrial revolution and the convergence of the world after the 1950s
Expand All @@ -544,7 +655,6 @@ mystnb:
caption: Regional GDP per capita
name: region_gdppc
---
fig = plt.figure(dpi=300)
ax = fig.gca()
line_styles = ['-', '--', ':', '-.', '.', 'o', '-', '--', '-']
Expand Down

1 comment on commit 1e8f135

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.