@@ -4,13 +4,15 @@ jupytext:
44 extension : .md
55 format_name : myst
66 format_version : 0.13
7- jupytext_version : 1.14.4
7+ jupytext_version : 1.14.5
88kernelspec :
99 display_name : Python 3 (ipykernel)
1010 language : python
1111 name : python3
1212---
1313
14+ +++ {"user_expressions": [ ] }
15+
1416# Long Run Growth
1517
1618## Overview
@@ -30,9 +32,11 @@ import numpy as np
3032from matplotlib.lines import Line2D
3133```
3234
33- ## Setting up
35+ +++ {"user_expressions": [ ] }
36+
37+ ## Setting up
3438
35- +++
39+ +++ {"user_expressions": [ ] }
3640
3741A project initiated by [ Angus Maddison] ( https://en.wikipedia.org/wiki/Angus_Maddison ) has collected many historical time series that study economic growth.
3842
@@ -49,6 +53,8 @@ data = pd.read_excel("datasets/mpd2020.xlsx", sheet_name='Full data')
4953data
5054```
5155
56+ +++ {"user_expressions": [ ] }
57+
5258We can see that this dataset contains GDP per capita (gdppc) and population (pop) for many countries and years.
5359
5460Let's look at how many and which countries are available in this dataset
@@ -57,6 +63,8 @@ Let's look at how many and which countries are available in this dataset
5763len(data.country.unique())
5864```
5965
66+ +++ {"user_expressions": [ ] }
67+
6068We can now explore some of the 169 countries that are available.
6169
6270Let's loop over each country to understand which years are available for each country
@@ -71,12 +79,16 @@ cntry_years = pd.DataFrame(cntry_years, columns=['country', 'Min Year', 'Max Yea
7179cntry_years
7280```
7381
82+ +++ {"user_expressions": [ ] }
83+
7484You can query this dataframe for each country of interest such as ` Australia ` by using ` .loc `
7585
7686``` {code-cell} ipython3
7787cntry_years.loc['Australia']
7888```
7989
90+ +++ {"user_expressions": [ ] }
91+
8092Let us now reshape the original data into some convenient variables to enable quicker access to countries time series data.
8193
8294We can build a useful mapping between country code's and country names in this dataset
@@ -85,6 +97,8 @@ We can build a useful mapping between country code's and country names in this d
8597code_to_name = data[['countrycode','country']].drop_duplicates().reset_index(drop=True).set_index(['countrycode'])
8698```
8799
100+ +++ {"user_expressions": [ ] }
101+
88102Then we can quickly focus on GDP per capita (gdp)
89103
90104``` {code-cell} ipython3
@@ -99,7 +113,7 @@ import numpy as np
99113country_names = data['countrycode']
100114
101115# Generate a colormap with the number of colors matching the number of countries
102- colors = cm.Dark2(np.linspace(0, 1 , len(country_names)))
116+ colors = cm.Dark2(np.linspace(0, 0.8 , len(country_names)))
103117
104118# Create a dictionary to map each country to its corresponding color
105119color_mapping = {country: color for country, color in zip(country_names, colors)}
@@ -114,6 +128,8 @@ gdppc = gdppc.unstack('countrycode')
114128gdppc
115129```
116130
131+ +++ {"user_expressions": [ ] }
132+
117133Looking at the United Kingdom we can first confirm we are using the correct country code
118134
119135``` {code-cell} ipython3
@@ -133,6 +149,8 @@ _ = gdppc[cntry].plot(
133149 color=color_mapping['GBR'])
134150```
135151
152+ +++ {"user_expressions": [ ] }
153+
136154We 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.
137155
138156Here we use dashed lines to indicate interpolated trends
@@ -160,6 +178,8 @@ ax.set_xlabel('Year')
160178plt.show()
161179```
162180
181+ +++ {"user_expressions": [ ] }
182+
163183We can now put this into a function to generate plots for a list of countries
164184
165185``` {code-cell} ipython3
@@ -192,6 +212,8 @@ def draw_interp_plots(series, xlabel, ylabel, color_mapping, code_to_name, lw, l
192212 return ax
193213```
194214
215+ +++ {"user_expressions": [ ] }
216+
195217:::{note}
196218[ 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).
197219:::
@@ -217,33 +239,94 @@ ax = draw_interp_plots(gdppc[cntry].loc[1200:],
217239b_params = {'color':'grey', 'alpha': 0.2}
218240t_params = {'fontsize': 5,
219241 'va':'center', 'ha':'center'}
220- ax.axvspan(1337, 1453, color=color_mapping['GBR'], alpha=0.2)
242+ ylim = ax.get_ylim()[1]
243+ ax.text(1320, ylim + ylim*0.2,
244+ 'the Great Famine\n(1315-1321)',
245+ color=color_mapping['GBR'], **t_params)
246+ ax.axvspan(1315, 1321, color=color_mapping['GBR'], alpha=0.2)
247+
248+ ax.text(1360, ylim + ylim*0.5,
249+ 'the Black Death\n(1348-1375)',
250+ color=color_mapping['GBR'], **t_params)
251+ ax.axvspan(1348, 1375, color=color_mapping['GBR'], alpha=0.2)
252+
253+ ax.text(1670, ylim + ylim*.2,
254+ 'the Navigation Act\n(1651-1696)',
255+ color=color_mapping['GBR'], **t_params)
256+ ax.axvspan(1651, 1696, color=color_mapping['GBR'], alpha=0.2)
257+ ax.text(1665, ylim + ylim*.5,
258+ 'Closed-door Policy\n(1655-1684)',
259+ color=color_mapping['CHN'], **t_params)
221260ax.axvspan(1655, 1684, color=color_mapping['CHN'], alpha=0.2)
222261ax.axvspan(1760, 1840, color='grey', alpha=0.2)
262+
263+ ax.text(1789, ylim + ylim*0.6,
264+ 'US Federation\n(1789)',
265+ color=color_mapping['USA'], **t_params)
223266ax.axvspan(1861, 1865, color=color_mapping['USA'], alpha=0.2)
224267ax.axvspan(1939, 1945, color='grey', alpha=0.2)
225268ax.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)
269+
230270ax.text(1800, ylim + ylim*0.2,
231271 'Industrial Revolution\n(1740-1860)',
232272 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)
239273ax.text(1941, ylim + ylim*0.2,
240274 'World War II\n(1939-1945)',
241275 color='grey', **t_params)
242276ax.text(1978, ylim + ylim*0.8,
243277 'Reform and Opening-up\n(1978-1979)',
244278 color=color_mapping['CHN'], **t_params)
279+
280+
281+ # fig, ax = plt.subplots(dpi=300)
282+
283+ # cntry = ['CHN', 'GBR', 'USA']
284+ # gdppc_change = gdppc[cntry].pct_change(periods=1) * 100
285+ # ax = draw_interp_plots(gdppc_change.loc[1200:],
286+ # 'International $\'s','Year',
287+ # color_mapping, code_to_name, 2, False, ax)
288+
289+ # b_params = {'color':'grey', 'alpha': 0.2}
290+ # t_params = {'fontsize': 5,
291+ # 'va':'center', 'ha':'center'}
292+ # ylim = ax.get_ylim()[1]
293+ # ax.text(1320, ylim + ylim*0.2,
294+ # 'the Great Famine\n(1315-1321)',
295+ # color=color_mapping['GBR'], **t_params)
296+ # ax.axvspan(1315, 1321, color=color_mapping['GBR'], alpha=0.2)
297+
298+ # ax.text(1360, ylim + ylim*0.5,
299+ # 'the Black Death\n(1348-1375)',
300+ # color=color_mapping['GBR'], **t_params)
301+ # ax.axvspan(1348, 1375, color=color_mapping['GBR'], alpha=0.2)
302+
303+ # ax.text(1670, ylim + ylim*.2,
304+ # 'Closed-door Policy\n(1651-1696)',
305+ # color=color_mapping['CHN'], **t_params)
306+ # ax.axvspan(1651, 1696, color=color_mapping['GBR'], alpha=0.2)
307+
308+ # ax.axvspan(1655, 1684, color=color_mapping['CHN'], alpha=0.2)
309+ # ax.axvspan(1760, 1840, color='grey', alpha=0.2)
310+ # ax.axvspan(1861, 1865, color=color_mapping['USA'], alpha=0.2)
311+ # ax.axvspan(1939, 1945, color='grey', alpha=0.2)
312+ # ax.axvspan(1978, 1979, color=color_mapping['CHN'], alpha=0.2)
313+
314+ # ax.text(1800, ylim + ylim*0.2,
315+ # 'Industrial Revolution\n(1740-1860)',
316+ # color='grey', **t_params)
317+ # ax.text(1863, ylim + ylim*0.6,
318+ # 'Act of Union\n(1861-1865)',
319+ # color=color_mapping['USA'], **t_params)
320+ # ax.text(1941, ylim + ylim*0.2,
321+ # 'World War II\n(1939-1945)',
322+ # color='grey', **t_params)
323+ # ax.text(1978, ylim + ylim*0.8,
324+ # 'Reform and Opening-up\n(1978-1979)',
325+ # color=color_mapping['CHN'], **t_params)
245326```
246327
328+ +++ {"user_expressions": [ ] }
329+
247330As 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.
248331
249332
@@ -258,6 +341,8 @@ data['gdp'] = data['gdppc'] * data['pop']
258341gdp = data['gdp'].unstack('countrycode')
259342```
260343
344+ +++ {"user_expressions": [ ] }
345+
261346### Early Industralization (1820 to 1940)
262347
263348
@@ -291,6 +376,8 @@ ax.legend(handles=legend_elements, loc='lower center', ncol=4, bbox_to_anchor=[0
291376plt.show()
292377```
293378
379+ +++ {"user_expressions": [ ] }
380+
294381GDP per Capita
295382
296383``` {code-cell} ipython3
@@ -321,6 +408,8 @@ ax.legend(handles=legend_elements, loc='lower center', ncol=4, bbox_to_anchor=[0
321408plt.show()
322409```
323410
411+ +++ {"user_expressions": [ ] }
412+
324413## The Modern Era (1970 to 2018)
325414
326415Gross Domestic Product (GDP)
@@ -353,6 +442,8 @@ ax.legend(handles=legend_elements, loc='lower center', ncol=4, bbox_to_anchor=[0
353442plt.show()
354443```
355444
445+ +++ {"user_expressions": [ ] }
446+
356447GDP per Capita
357448
358449``` {code-cell} ipython3
@@ -383,6 +474,8 @@ ax.legend(handles=legend_elements, loc='lower center', ncol=3, bbox_to_anchor=[0
383474plt.show()
384475```
385476
477+ +++ {"user_expressions": [ ] }
478+
386479## Other Interesting Plots
387480
388481Here are a collection of interesting plots that could be linked to interesting stories
@@ -395,6 +488,8 @@ gdppc['CHN'].loc[1500:1980].interpolate().plot(ax=fig.gca())
395488plt.show()
396489```
397490
491+ +++ {"user_expressions": [ ] }
492+
398493China (CHN) then followed a very similar growth story from the 1980s through to current day China.
399494
400495``` {code-cell} ipython3
@@ -403,6 +498,8 @@ gdppc[['CHN', 'GBR']].interpolate().plot(ax = fig.gca())
403498plt.show()
404499```
405500
501+ +++ {"user_expressions": [ ] }
502+
406503## Regional Analysis
407504
408505The [ Maddison Historical Statistics] ( https://www.rug.nl/ggdc/historicaldevelopment/maddison/ ) dataset also includes regional aggregations
@@ -412,19 +509,25 @@ data = pd.read_excel("datasets/mpd2020.xlsx", sheet_name='Regional data', header
412509data.columns = data.columns.droplevel(level=2)
413510```
414511
512+ +++ {"user_expressions": [ ] }
513+
415514We can save the raw data in a more convenient format to build a single table of regional GDP per capita
416515
417516``` {code-cell} ipython3
418517regionalgdppc = data['gdppc_2011'].copy()
419518regionalgdppc.index = pd.to_datetime(regionalgdppc.index, format='%Y')
420519```
421520
521+ +++ {"user_expressions": [ ] }
522+
422523Let us interpolate based on time to fill in any gaps in the dataset for the purpose of plotting
423524
424525``` {code-cell} ipython3
425526regionalgdppc.interpolate(method='time', inplace=True)
426527```
427528
529+ +++ {"user_expressions": [ ] }
530+
428531and record a dataset of world GDP per capita
429532
430533``` {code-cell} ipython3
@@ -442,9 +545,11 @@ ax = worldgdppc.plot(
442545)
443546```
444547
548+ +++ {"user_expressions": [ ] }
549+
445550Looking more closely, let us compare the time series for ` Western Offshoots ` and ` Sub-Saharan Africa `
446551
447- +++
552+ +++ {"user_expressions": [ ] }
448553
449554and more broadly at a number of different regions around the world
450555
0 commit comments