Skip to content

Commit 65dd6ca

Browse files
committed
edit long_run_growth
1 parent b2d5885 commit 65dd6ca

File tree

1 file changed

+110
-96
lines changed

1 file changed

+110
-96
lines changed

lectures/long_run_growth.md

Lines changed: 110 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jupytext:
44
extension: .md
55
format_name: myst
66
format_version: 0.13
7-
jupytext_version: 1.14.5
7+
jupytext_version: 1.14.4
88
kernelspec:
99
display_name: Python 3 (ipykernel)
1010
language: python
@@ -13,16 +13,6 @@ kernelspec:
1313

1414
# Long Run Growth
1515

16-
```{admonition} Lecture IN-WORK
17-
:class: warning
18-
19-
This lecture is still **under construction**
20-
```
21-
22-
```{contents} Contents
23-
:depth: 2
24-
```
25-
2616
## Overview
2717

2818
This lecture looks at different growth trajectories across countries over the long term.
@@ -40,13 +30,16 @@ import numpy as np
4030
from matplotlib.lines import Line2D
4131
```
4232

33+
## Setting up
34+
35+
+++
4336

4437
A project initiated by [Angus Maddison](https://en.wikipedia.org/wiki/Angus_Maddison) has collected many historical time series that study economic growth.
4538

4639
We can use the [Maddison Historical Statistics](https://www.rug.nl/ggdc/historicaldevelopment/maddison/) to look at many different countries, including some countries dating back to the first century.
4740

4841
```{tip}
49-
The data can be downloaded from [this webpage](https://www.rug.nl/ggdc/historicaldevelopment/maddison/) and clicking on the `Latest Maddison Project Release`. In this lecture we use the [Maddison Project Database 2020](https://www.rug.nl/ggdc/historicaldevelopment/maddison/releases/maddison-project-database-2020) using the `Excel` Format. The code we use here assumes you have downloaded that file and will teach you how to use [pandas](https://pandas.pydata.org) to import that data into a DataFrame.
42+
The data can be downloaded from [this webpage](https://www.rug.nl/ggdc/historicaldevelopment/maddison/) and clicking on the `Latest Maddison Project Release`. In this lecture we use the [Maddison Project Database 2020](https://www.rug.nl/ggdc/historicaldevelopment/maddison/releases/maddison-project-database-2020) using the `Excel` Format.
5043
```
5144

5245
If you don't want to fetch the data file from [Maddison Historical Statistics](https://www.rug.nl/ggdc/historicaldevelopment/maddison/) you can download the file directly {download}`datasets/mpd2020.xlsx`.
@@ -60,10 +53,6 @@ We can see that this dataset contains GDP per capita (gdppc) and population (pop
6053

6154
Let's look at how many and which countries are available in this dataset
6255

63-
```{code-cell} ipython3
64-
data.country.unique()
65-
```
66-
6756
```{code-cell} ipython3
6857
len(data.country.unique())
6958
```
@@ -102,6 +91,20 @@ Then we can quickly focus on GDP per capita (gdp)
10291
data
10392
```
10493

94+
```{code-cell} ipython3
95+
import matplotlib.pyplot as plt
96+
import matplotlib.cm as cm
97+
import numpy as np
98+
99+
country_names = data['countrycode']
100+
101+
# Generate a colormap with the number of colors matching the number of countries
102+
colors = cm.Dark2(np.linspace(0, 1, len(country_names)))
103+
104+
# Create a dictionary to map each country to its corresponding color
105+
color_mapping = {country: color for country, color in zip(country_names, colors)}
106+
```
107+
105108
```{code-cell} ipython3
106109
gdppc = data.set_index(['countrycode','year'])['gdppc']
107110
gdppc = gdppc.unstack('countrycode')
@@ -113,43 +116,82 @@ gdppc
113116

114117
Looking at the United Kingdom we can first confirm we are using the correct country code
115118

116-
```{code-cell} ipython3
117-
code_to_name.loc['GBR']
118-
```
119-
120-
and then using that code to access and plot the data
121-
122119
```{code-cell} ipython3
123120
---
124121
mystnb:
125122
figure:
126123
caption: GDP per Capita (GBR)
127124
name: gdppc_gbr1
128125
---
129-
fig = plt.figure()
130-
gdppc['GBR'].plot(ax = fig.gca())
131-
plt.show()
126+
fig, ax = plt.subplots(dpi=300)
127+
cntry = 'GBR'
128+
_ = gdppc[cntry].plot(
129+
ax = fig.gca(),
130+
ylabel = 'International $\'s',
131+
xlabel = 'Year',
132+
linestyle='-',
133+
color=color_mapping['GBR'])
132134
```
133135

134136
We can see that the data is non-continuous for longer periods in early part of this milenium so we could choose to interpolate to get a continuous line plot.
135137

138+
Here we use dashed lines to indicate interpolated trends
139+
136140
```{code-cell} ipython3
137141
---
138142
mystnb:
139143
figure:
140144
caption: GDP per Capita (GBR)
141145
name: gdppc_gbr2
142146
---
143-
fig = plt.figure(dpi=300)
147+
fig, ax = plt.subplots(dpi=300)
144148
cntry = 'GBR'
145-
gdppc[cntry].interpolate().plot(
146-
ax = fig.gca(),
147-
ylabel = 'International $\'s',
148-
xlabel = 'Year'
149-
)
149+
ax.plot(gdppc[cntry].interpolate(),
150+
linestyle='--',
151+
lw=2,
152+
color=color_mapping[cntry])
153+
154+
ax.plot(gdppc[cntry],
155+
linestyle='-',
156+
lw=2,
157+
color=color_mapping[cntry])
158+
ax.set_ylabel('International $\'s')
159+
ax.set_xlabel('Year')
150160
plt.show()
151161
```
152162

163+
We can now put this into a function to generate plots for a list of countries
164+
165+
```{code-cell} ipython3
166+
def draw_interp_plots(series, xlabel, ylabel, color_mapping, code_to_name, lw, logscale, ax):
167+
168+
for i, c in enumerate(cntry):
169+
170+
df_interpolated = series[c].interpolate()
171+
interpolated_data = df_interpolated[series[c].isnull()]
172+
ax.plot(interpolated_data,
173+
linestyle='--',
174+
lw=lw,
175+
alpha=0.7,
176+
color=color_mapping[c])
177+
178+
ax.plot(series[c],
179+
linestyle='-',
180+
lw=lw,
181+
color=color_mapping[c],
182+
alpha=0.8,
183+
label=code_to_name.loc[c]['country'])
184+
185+
if logscale == True:
186+
ax.set_yscale('log')
187+
188+
ax.legend(loc='lower center', ncol=3, bbox_to_anchor=[0.5, -0.25])
189+
ax.set_xlabel(xlabel)
190+
ax.set_ylabel(ylabel)
191+
192+
return ax
193+
```
194+
153195
:::{note}
154196
[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 and any given time. They are also known as Geary–Khamis dollar (GK Dollars).
155197
:::
@@ -165,55 +207,41 @@ mystnb:
165207
caption: GDP per Capita
166208
name: gdppc_usa_gbr_chn
167209
---
168-
fig = plt.figure(dpi=300)
169-
ax = fig.gca()
170-
cntry = ['USA', 'GBR', 'CHN']
171-
line_color = ['blue', 'orange', 'green']
172-
gdppc[cntry].plot(
173-
ax = ax,
174-
ylabel = 'International $\'s',
175-
xlabel = 'Year',
176-
color = line_color
177-
)
178-
179-
# Build Custom Legend
180-
legend_elements = []
181-
for i,c in enumerate(cntry):
182-
line = Line2D([0], [0], color=line_color[i], lw=2, label=code_to_name.loc[c]['country'])
183-
legend_elements.append(line)
184-
ax.legend(handles=legend_elements, loc='lower center', ncol=3, bbox_to_anchor=[0.5, -0.25])
185-
plt.show()
186-
```
187-
188-
This dataset has been carefully curated to enable cross-country comparisons.
189-
190-
Let's compare the growth trajectories of Australia (AUS) and Argentina (ARG)
191-
192-
```{code-cell} ipython3
193-
---
194-
mystnb:
195-
figure:
196-
caption: GDP per capita
197-
name: gdppc_aus_arg
198-
---
199-
fig = plt.figure(dpi=300)
200-
ax = fig.gca()
201-
cntry = ['AUS', 'ARG']
202-
line_color = ['blue', 'orange']
203-
gdppc[cntry].plot(
204-
ax = ax,
205-
ylabel = 'International $\'s',
206-
xlabel = 'Year',
207-
color = line_color
208-
)
209-
210-
# Build Custom Legend
211-
legend_elements = []
212-
for i,c in enumerate(cntry):
213-
line = Line2D([0], [0], color=line_color[i], lw=2, label=code_to_name.loc[c]['country'])
214-
legend_elements.append(line)
215-
ax.legend(handles=legend_elements, loc='lower center', ncol=3, bbox_to_anchor=[0.5, -0.25])
216-
plt.show()
210+
fig, ax = plt.subplots(dpi=300)
211+
212+
cntry = ['CHN', 'GBR', 'USA']
213+
ax = draw_interp_plots(gdppc[cntry].loc[1200:],
214+
'International $\'s','Year',
215+
color_mapping, code_to_name, 2, True, ax)
216+
217+
b_params = {'color':'grey', 'alpha': 0.2}
218+
t_params = {'fontsize': 5,
219+
'va':'center', 'ha':'center'}
220+
ax.axvspan(1337, 1453, color=color_mapping['GBR'], alpha=0.2)
221+
ax.axvspan(1655, 1684, color=color_mapping['CHN'], alpha=0.2)
222+
ax.axvspan(1760, 1840, color='grey', alpha=0.2)
223+
ax.axvspan(1861, 1865, color=color_mapping['USA'], alpha=0.2)
224+
ax.axvspan(1939, 1945, color='grey', alpha=0.2)
225+
ax.axvspan(1978, 1979, color=color_mapping['CHN'], alpha=0.2)
226+
ylim = ax.get_ylim()[1]
227+
ax.text(1395, ylim + ylim*0.2,
228+
'Hundred Years\' War\n(1337-1453)',
229+
color=color_mapping['GBR'], **t_params)
230+
ax.text(1800, ylim + ylim*0.2,
231+
'Industrial Revolution\n(1740-1860)',
232+
color='grey', **t_params)
233+
ax.text(1665, ylim + ylim*.2,
234+
'Closed-door Policy\n(1655-1684)',
235+
color=color_mapping['CHN'], **t_params)
236+
ax.text(1863, ylim + ylim*0.6,
237+
'American Civil War\n(1861-1865)',
238+
color=color_mapping['USA'], **t_params)
239+
ax.text(1941, ylim + ylim*0.2,
240+
'World War II\n(1939-1945)',
241+
color='grey', **t_params)
242+
ax.text(1978, ylim + ylim*0.8,
243+
'Reform and Opening-up\n(1978-1979)',
244+
color=color_mapping['CHN'], **t_params)
217245
```
218246

219247
As you can see the countries had similar GDP per capita levels with divergence starting around 1940. Australia's growth experience is both more continuous and less volatile post 1940.
@@ -230,7 +258,6 @@ data['gdp'] = data['gdppc'] * data['pop']
230258
gdp = data['gdp'].unstack('countrycode')
231259
```
232260

233-
234261
### Early Industralization (1820 to 1940)
235262

236263

@@ -356,7 +383,6 @@ ax.legend(handles=legend_elements, loc='lower center', ncol=3, bbox_to_anchor=[0
356383
plt.show()
357384
```
358385

359-
360386
## Other Interesting Plots
361387

362388
Here are a collection of interesting plots that could be linked to interesting stories
@@ -369,7 +395,6 @@ gdppc['CHN'].loc[1500:1980].interpolate().plot(ax=fig.gca())
369395
plt.show()
370396
```
371397

372-
373398
China (CHN) then followed a very similar growth story from the 1980s through to current day China.
374399

375400
```{code-cell} ipython3
@@ -378,7 +403,6 @@ gdppc[['CHN', 'GBR']].interpolate().plot(ax = fig.gca())
378403
plt.show()
379404
```
380405

381-
382406
## Regional Analysis
383407

384408
The [Maddison Historical Statistics](https://www.rug.nl/ggdc/historicaldevelopment/maddison/) dataset also includes regional aggregations
@@ -388,22 +412,19 @@ data = pd.read_excel("datasets/mpd2020.xlsx", sheet_name='Regional data', header
388412
data.columns = data.columns.droplevel(level=2)
389413
```
390414

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

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

399-
400422
Let us interpolate based on time to fill in any gaps in the dataset for the purpose of plotting
401423

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

406-
407428
and record a dataset of world GDP per capita
408429

409430
```{code-cell} ipython3
@@ -421,17 +442,9 @@ ax = worldgdppc.plot(
421442
)
422443
```
423444

424-
425445
Looking more closely, let us compare the time series for `Western Offshoots` and `Sub-Saharan Africa`
426446

427-
```{code-cell} ipython3
428-
fig = plt.figure(dpi=300)
429-
ax = fig.gca()
430-
regionalgdppc[['Western Offshoots', 'Sub-Sahara Africa']].plot(ax = ax)
431-
ax.legend(loc='lower center', ncol=2, bbox_to_anchor=[0.5, -0.26])
432-
plt.show()
433-
```
434-
447+
+++
435448

436449
and more broadly at a number of different regions around the world
437450

@@ -440,6 +453,7 @@ fig = plt.figure(dpi=300)
440453
ax = fig.gca()
441454
line_styles = ['-', '--', ':', '-.', '.', 'o', '-', '--', '-']
442455
ax = regionalgdppc.plot(ax = ax, style=line_styles)
456+
ax.set_yscale('log')
443457
plt.legend(loc='lower center', ncol=3, bbox_to_anchor=[0.5, -0.4])
444458
plt.show()
445459
```

0 commit comments

Comments
 (0)