From 76f7f9334840977185fc13715a78a5593ac6de2f Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Tue, 21 Feb 2023 21:07:08 +1100 Subject: [PATCH 1/8] update business cycle lecture --- in-work/ business_cycle.md | 164 +++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 in-work/ business_cycle.md diff --git a/in-work/ business_cycle.md b/in-work/ business_cycle.md new file mode 100644 index 000000000..101129ae9 --- /dev/null +++ b/in-work/ business_cycle.md @@ -0,0 +1,164 @@ +--- +jupytext: + text_representation: + extension: .md + format_name: myst + format_version: 0.13 + jupytext_version: 1.14.4 +kernelspec: + display_name: Python 3 (ipykernel) + language: python + name: python3 +--- + +```{code-cell} ipython3 +!pip install wbgapi +``` + +# Business Cycle + +## Overview + +This lecture is about illustrateing business cycles in different countries and period. + +Business cycle is one of the widely studied field since the birth of economics as a subject from . + +In this lecture, we will see expensions and contractions of economies throughout the history with an emphasise on contemprary business cycles. + +We use the following imports. + +```{code-cell} ipython3 +import matplotlib.pyplot as plt +import pandas as pd +import numpy as np +import scipy.stats as st +import wbgapi as wb +``` + +```{code-cell} ipython3 +wb.series.info(q='GDP growth') +``` + +```{code-cell} ipython3 +wb.series.info(q='unemployment') +``` + +```{code-cell} ipython3 +wb.series.info(q='credit') +``` + +## GDP Growth Rate and Unemployment + +First we look at the GDP growth rate and unemployment rate. + +Let's source our data from the World Bank and clean the data + +```{code-cell} ipython3 +gdp_growth = wb.data.DataFrame('NY.GDP.MKTP.KD.ZG',['CHN', 'USA', 'DEU', 'BRA', 'ARG', 'GBR'], labels=True) +gdp_growth = gdp_growth.set_index('Country') +gdp_growth.columns = gdp_growth.columns.str.replace('YR', '').astype(int) +``` + +```{code-cell} ipython3 +gdp_growth +``` + +```{code-cell} ipython3 +fig, ax = plt.subplots() +plt.locator_params(axis='x', nbins=10) +cycler = plt.cycler(linestyle=['-', '-.', '--'], color=['#377eb8', '#ff7f00', '#4daf4a']) +plt.rc('axes', prop_cycle=cycler) +ax.set_xticks([i for i in range(1960, 2021, 10)], minor=False) + +def plot_comparison(data, countries, title, ylabel, title_pos, ax, g_params, b_params, t_params): + for country in countries: + ax.plot(data.loc[country], label=country, **g_params) + # ax.plot(data.loc[country, 1990:1992], alpha=0.8) + # ax.plot(data.loc[country, 1973:1975], alpha=0.8) + # ax.plot(data.loc[country, 2007:2009], alpha=0.8) + # ax.plot(data.loc[country, 2019:2021], alpha=0.8) + ax.axvspan(1973, 1975, **b_params) + ax.axvspan(1990, 1992, **b_params) + ax.axvspan(2007, 2009, **b_params) + ax.axvspan(2019, 2021, **b_params) + ylim = ax.get_ylim()[1] + ax.text(1974, ylim + ylim * title_pos, 'Oil Crisis\n(1974)', **t_params) + ax.text(1991, ylim + ylim * title_pos, '1990s recession\n(1991)', **t_params) + ax.text(2008, ylim + ylim * title_pos, 'GFC\n(2008)', **t_params) + ax.text(2020, ylim + ylim * title_pos, 'Covid-19\n(2020)', **t_params) + ax.set_title(title, pad=40) + ax.set_ylabel('GDP Growth Rate (%)') + ax.legend() + return ax + +g_params = {'alpha': 0.7} +b_params = {'color':'grey', 'alpha': 0.2} +t_params = {'color':'grey', 'fontsize': 9, 'va':'center', 'ha':'center'} +countries = ['United Kingdom', 'United States', 'Germany'] +title = 'United Kingdom, United States, and Germany (GDP Growth Rate %)' +ylabel = 'GDP Growth Rate (%)' +title_height = 0.1 +ax = plot_comparison(gdp_growth, countries, title, ylabel, 0.1, ax, g_params, b_params, t_params) +``` + +```{code-cell} ipython3 +fig, ax = plt.subplots() + +countries = ['Brazil', 'China', 'Argentina'] +title = 'Brazil, China, Argentina (GDP Growth Rate %)' +ax = plot_comparison(gdp_growth, countries, title, ylabel, 0.1, ax, g_params, b_params, t_params) +``` + +```{code-cell} ipython3 +unempl_rate = wb.data.DataFrame('SL.UEM.TOTL.NE.ZS',['CHN', 'USA', 'DEU', 'BRA', 'ARG', 'GBR'], labels=True) +unempl_rate = unempl_rate.set_index('Country') +unempl_rate.columns = unempl_rate.columns.str.replace('YR', '').astype(int) +``` + +```{code-cell} ipython3 +unempl_rate +``` + +```{code-cell} ipython3 +fig, ax = plt.subplots() + +countries = ['United Kingdom', 'United States', 'Germany'] +title = 'United Kingdom, United States, and Germany (Unemployment Rate %)' +ylabel = 'Unemployment Rate (National Estimate) (%)' +ax = plot_comparison(unempl_rate, countries, title, ylabel, 0.03, ax, g_params, b_params, t_params) +``` + +```{code-cell} ipython3 +fig, ax = plt.subplots() + +countries = ['Brazil', 'China', 'Argentina'] +title = 'Brazil, China, Argentina (Unemployment Rate %)' +ax = plot_comparison(unempl_rate, countries, title, ylabel, 0.04, ax, g_params, b_params, t_params) +``` + +```{code-cell} ipython3 +private_credit = wb.data.DataFrame('FD.AST.PRVT.GD.ZS',['CHN', 'USA', 'DEU', 'BRA', 'ARG', 'GBR'], labels=True) +private_credit = private_credit.set_index('Country') +private_credit.columns = private_credit.columns.str.replace('YR', '').astype(int) +``` + +```{code-cell} ipython3 +private_credit +``` + +```{code-cell} ipython3 +fig, ax = plt.subplots() + +countries = ['United Kingdom', 'United States', 'Germany'] +title = 'United Kingdom, United States, and Germany \n Domestic credit to private sector by banks (% of GDP)' +ylabel = '% of GDP)' +ax = plot_comparison(unempl_rate, countries, title, '% of GDP', 0.05, ax, g_params, b_params, t_params) +``` + +```{code-cell} ipython3 +fig, ax = plt.subplots() + +countries = ['Brazil', 'China', 'Argentina'] +title = 'Brazil, China, Argentina \n Domestic credit to private sector by banks (% of GDP)' +ax = plot_comparison(unempl_rate, countries, title, ylabel, 0.05, ax, g_params, b_params, t_params) +``` From a5375846f29a98f1cbbd521a887b6e75039d0961 Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Tue, 21 Feb 2023 21:13:40 +1100 Subject: [PATCH 2/8] fix small bugs --- .github/workflows/ci.yml | 2 +- in-work/ business_cycle.md | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e85a2f484..1dc38c8b4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,5 @@ name: Build HTML [using jupyter-book] -on: [push] +on: [pull_request] jobs: tests: runs-on: ubuntu-latest diff --git a/in-work/ business_cycle.md b/in-work/ business_cycle.md index 101129ae9..1657338b6 100644 --- a/in-work/ business_cycle.md +++ b/in-work/ business_cycle.md @@ -87,7 +87,7 @@ def plot_comparison(data, countries, title, ylabel, title_pos, ax, g_params, b_p ax.text(2008, ylim + ylim * title_pos, 'GFC\n(2008)', **t_params) ax.text(2020, ylim + ylim * title_pos, 'Covid-19\n(2020)', **t_params) ax.set_title(title, pad=40) - ax.set_ylabel('GDP Growth Rate (%)') + ax.set_ylabel(ylabel) ax.legend() return ax @@ -151,8 +151,8 @@ fig, ax = plt.subplots() countries = ['United Kingdom', 'United States', 'Germany'] title = 'United Kingdom, United States, and Germany \n Domestic credit to private sector by banks (% of GDP)' -ylabel = '% of GDP)' -ax = plot_comparison(unempl_rate, countries, title, '% of GDP', 0.05, ax, g_params, b_params, t_params) +ylabel = '% of GDP' +ax = plot_comparison(private_credit, countries, title, ylabel, 0.05, ax, g_params, b_params, t_params) ``` ```{code-cell} ipython3 @@ -160,5 +160,5 @@ fig, ax = plt.subplots() countries = ['Brazil', 'China', 'Argentina'] title = 'Brazil, China, Argentina \n Domestic credit to private sector by banks (% of GDP)' -ax = plot_comparison(unempl_rate, countries, title, ylabel, 0.05, ax, g_params, b_params, t_params) +ax = plot_comparison(private_credit, countries, title, ylabel, 0.05, ax, g_params, b_params, t_params) ``` From 92aaa0127793e43fb2d4455b1eb1c35c7826e87d Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Tue, 21 Feb 2023 21:24:42 +1100 Subject: [PATCH 3/8] update cpi --- in-work/ business_cycle.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/in-work/ business_cycle.md b/in-work/ business_cycle.md index 1657338b6..e5c138698 100644 --- a/in-work/ business_cycle.md +++ b/in-work/ business_cycle.md @@ -47,6 +47,10 @@ wb.series.info(q='unemployment') wb.series.info(q='credit') ``` +```{code-cell} ipython3 +wb.series.info(q='consumer') +``` + ## GDP Growth Rate and Unemployment First we look at the GDP growth rate and unemployment rate. @@ -162,3 +166,30 @@ countries = ['Brazil', 'China', 'Argentina'] title = 'Brazil, China, Argentina \n Domestic credit to private sector by banks (% of GDP)' ax = plot_comparison(private_credit, countries, title, ylabel, 0.05, ax, g_params, b_params, t_params) ``` + +```{code-cell} ipython3 +cpi = wb.data.DataFrame('FP.CPI.TOTL.ZG',['CHN', 'USA', 'DEU', 'BRA', 'ARG', 'GBR'], labels=True) +cpi = cpi.set_index('Country') +cpi.columns = cpi.columns.str.replace('YR', '').astype(int) +``` + +```{code-cell} ipython3 +cpi +``` + +```{code-cell} ipython3 +fig, ax = plt.subplots() + +countries = ['United Kingdom', 'United States', 'Germany'] +title = 'United Kingdom, United States, and Germany \n Domestic credit to private sector by banks (% of GDP)' +ylabel = '% of GDP' +ax = plot_comparison(cpi, countries, title, ylabel, 0.05, ax, g_params, b_params, t_params) +``` + +```{code-cell} ipython3 +fig, ax = plt.subplots() + +countries = ['Brazil', 'China', 'Argentina'] +title = 'Brazil, China, Argentina \n Domestic credit to private sector by banks (% of GDP)' +ax = plot_comparison(cpi, countries, title, ylabel, 0.05, ax, g_params, b_params, t_params) +``` From 588c057b6be0f7962cc8998620ba16d57a3a3619 Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Mon, 27 Feb 2023 10:20:13 +1100 Subject: [PATCH 4/8] add plots --- in-work/ business_cycle.md | 146 +++++++++++++++++++++++++++++++++---- 1 file changed, 133 insertions(+), 13 deletions(-) diff --git a/in-work/ business_cycle.md b/in-work/ business_cycle.md index e5c138698..a75d3e11f 100644 --- a/in-work/ business_cycle.md +++ b/in-work/ business_cycle.md @@ -51,6 +51,10 @@ wb.series.info(q='credit') wb.series.info(q='consumer') ``` +```{code-cell} ipython3 +wb.series.info(q='consumption') +``` + ## GDP Growth Rate and Unemployment First we look at the GDP growth rate and unemployment rate. @@ -58,7 +62,7 @@ First we look at the GDP growth rate and unemployment rate. Let's source our data from the World Bank and clean the data ```{code-cell} ipython3 -gdp_growth = wb.data.DataFrame('NY.GDP.MKTP.KD.ZG',['CHN', 'USA', 'DEU', 'BRA', 'ARG', 'GBR'], labels=True) +gdp_growth = wb.data.DataFrame('NY.GDP.MKTP.KD.ZG',['CHN', 'USA', 'DEU', 'BRA', 'ARG', 'GBR', 'MEX', 'CHL', 'COL', 'SLV', 'HTI'], labels=True) gdp_growth = gdp_growth.set_index('Country') gdp_growth.columns = gdp_growth.columns.str.replace('YR', '').astype(int) ``` @@ -68,19 +72,18 @@ gdp_growth ``` ```{code-cell} ipython3 -fig, ax = plt.subplots() -plt.locator_params(axis='x', nbins=10) cycler = plt.cycler(linestyle=['-', '-.', '--'], color=['#377eb8', '#ff7f00', '#4daf4a']) plt.rc('axes', prop_cycle=cycler) +``` + +```{code-cell} ipython3 +fig, ax = plt.subplots() ax.set_xticks([i for i in range(1960, 2021, 10)], minor=False) +plt.locator_params(axis='x', nbins=10) def plot_comparison(data, countries, title, ylabel, title_pos, ax, g_params, b_params, t_params): for country in countries: ax.plot(data.loc[country], label=country, **g_params) - # ax.plot(data.loc[country, 1990:1992], alpha=0.8) - # ax.plot(data.loc[country, 1973:1975], alpha=0.8) - # ax.plot(data.loc[country, 2007:2009], alpha=0.8) - # ax.plot(data.loc[country, 2019:2021], alpha=0.8) ax.axvspan(1973, 1975, **b_params) ax.axvspan(1990, 1992, **b_params) ax.axvspan(2007, 2009, **b_params) @@ -110,11 +113,88 @@ fig, ax = plt.subplots() countries = ['Brazil', 'China', 'Argentina'] title = 'Brazil, China, Argentina (GDP Growth Rate %)' -ax = plot_comparison(gdp_growth, countries, title, ylabel, 0.1, ax, g_params, b_params, t_params) +ax = plot_comparison(gdp_growth.loc[countries, 1962:], countries, title, ylabel, 0.1, ax, g_params, b_params, t_params) +``` + +```{code-cell} ipython3 +def plot_comparison_NBER(data, countries, title, ylabel, title_pos, ax, g_params, b_params, t_params): + for country in countries: + ax.plot(data.loc[country], label=country, **g_params) + ax.axvspan(1969, 1970, **b_params) + ax.axvspan(1973, 1975, **b_params) + ax.axvspan(1980.25, 1980.75, **b_params) + ax.axvspan(1981, 1982, **b_params) + ax.axvspan(1990, 1991, **b_params) + ax.axvspan(2001.25, 2002, **b_params) + ax.axvspan(2007, 2009, **b_params) + ax.axvspan(2020, 2020, **b_params) + ylim = ax.get_ylim()[1] + ax.text(1974, ylim + ylim * title_pos, 'Oil Crisis\n(1974)', **t_params) + ax.text(1991, ylim + ylim * title_pos, '1990s recession\n(1991)', **t_params) + ax.text(2008, ylim + ylim * title_pos, 'GFC\n(2008)', **t_params) + ax.text(2020, ylim + ylim * title_pos, 'Covid-19\n(2020)', **t_params) + ax.set_title(title, pad=40) + ax.set_ylabel(ylabel) + ax.legend() + return ax + +fig, ax = plt.subplots() + +countries = ['United States'] +title = 'United States (GDP Growth Rate %)' +ax = plot_comparison_NBER(gdp_growth.loc[countries, 1962:], countries, title, ylabel, 0.1, ax, g_params, b_params, t_params) +``` + +```{code-cell} ipython3 +fig, ax = plt.subplots() + +countries = ['Argentina'] +title = 'Argentina (GDP Growth Rate %)' +ax = plot_comparison(gdp_growth.loc[countries, 1962:], countries, title, ylabel, 0.1, ax, g_params, b_params, t_params) +``` + +```{code-cell} ipython3 +fig, ax = plt.subplots() + +countries = ['Mexico'] +title = 'Mexico (GDP Growth Rate %)' +ax = plot_comparison(gdp_growth.loc[countries, 1962:], countries, title, ylabel, 0.1, ax, g_params, b_params, t_params) +``` + +```{code-cell} ipython3 +fig, ax = plt.subplots() + +countries = ['Chile'] +title = 'Chile (GDP Growth Rate %)' +ax = plot_comparison(gdp_growth.loc[countries, 1962:], countries, title, ylabel, 0.1, ax, g_params, b_params, t_params) +``` + +```{code-cell} ipython3 +fig, ax = plt.subplots() + +countries = ['Colombia'] +title = 'Colombia (GDP Growth Rate %)' +ax = plot_comparison(gdp_growth.loc[countries, 1962:], countries, title, ylabel, 0.1, ax, g_params, b_params, t_params) +``` + +```{code-cell} ipython3 +fig, ax = plt.subplots() + +countries = ['El Salvador'] +title = 'El Salvador (GDP Growth Rate %)' +ax = plot_comparison(gdp_growth.loc[countries, 1962:], countries, title, ylabel, 0.1, ax, g_params, b_params, t_params) +``` + +```{code-cell} ipython3 +fig, ax = plt.subplots() + +countries = ['Haiti'] +title = 'Haiti (GDP Growth Rate %)' +ax = plot_comparison(gdp_growth.loc[countries, 1962:], countries, title, ylabel, 0.1, ax, g_params, b_params, t_params) ``` ```{code-cell} ipython3 -unempl_rate = wb.data.DataFrame('SL.UEM.TOTL.NE.ZS',['CHN', 'USA', 'DEU', 'BRA', 'ARG', 'GBR'], labels=True) +unempl_rate = wb.data.DataFrame('SL.UEM.TOTL.NE.ZS',['CHN', 'USA', 'DEU', 'BRA', 'ARG', 'GBR', 'MEX', 'CHL', 'COL', 'SLV', 'HTI'], labels=True) unempl_rate = unempl_rate.set_index('Country') unempl_rate.columns = unempl_rate.columns.str.replace('YR', '').astype(int) ``` @@ -140,6 +220,38 @@ title = 'Brazil, China, Argentina (Unemployment Rate %)' ax = plot_comparison(unempl_rate, countries, title, ylabel, 0.04, ax, g_params, b_params, t_params) ``` +```{code-cell} ipython3 +fig, ax = plt.subplots() + +countries = ['Brazil'] +title = 'Brazil (Unemployment Rate %)' +ax = plot_comparison(unempl_rate, countries, title, ylabel, 0.04, ax, g_params, b_params, t_params) +``` + +```{code-cell} ipython3 +fig, ax = plt.subplots() + +countries = ['Chile'] +title = 'Chile (Unemployment Rate %)' +ax = plot_comparison(unempl_rate, countries, title, ylabel, 0.04, ax, g_params, b_params, t_params) +``` + +```{code-cell} ipython3 +fig, ax = plt.subplots() + +countries = ['Colombia'] +title = 'Colombia (Unemployment Rate %)' +ax = plot_comparison(unempl_rate, countries, title, ylabel, 0.04, ax, g_params, b_params, t_params) +``` + +```{code-cell} ipython3 +fig, ax = plt.subplots() + +countries = ['El Salvador'] +title = 'El Salvador (Unemployment Rate %)' +ax = plot_comparison(unempl_rate, countries, title, ylabel, 0.04, ax, g_params, b_params, t_params) +``` + ```{code-cell} ipython3 private_credit = wb.data.DataFrame('FD.AST.PRVT.GD.ZS',['CHN', 'USA', 'DEU', 'BRA', 'ARG', 'GBR'], labels=True) private_credit = private_credit.set_index('Country') @@ -167,6 +279,14 @@ title = 'Brazil, China, Argentina \n Domestic credit to private sector by banks ax = plot_comparison(private_credit, countries, title, ylabel, 0.05, ax, g_params, b_params, t_params) ``` +```{code-cell} ipython3 +fig, ax = plt.subplots() + +countries = ['United Kingdom', 'China'] +title = 'United Kingdom and China \n Domestic credit to private sector by banks (% of GDP)' +ax = plot_comparison(private_credit, countries, title, ylabel, 0.05, ax, g_params, b_params, t_params) +``` + ```{code-cell} ipython3 cpi = wb.data.DataFrame('FP.CPI.TOTL.ZG',['CHN', 'USA', 'DEU', 'BRA', 'ARG', 'GBR'], labels=True) cpi = cpi.set_index('Country') @@ -181,15 +301,15 @@ cpi fig, ax = plt.subplots() countries = ['United Kingdom', 'United States', 'Germany'] -title = 'United Kingdom, United States, and Germany \n Domestic credit to private sector by banks (% of GDP)' -ylabel = '% of GDP' +title = 'United Kingdom, United States, and Germany \n Inflation, consumer prices (annual %)' +ylabel = 'annual %' ax = plot_comparison(cpi, countries, title, ylabel, 0.05, ax, g_params, b_params, t_params) ``` ```{code-cell} ipython3 fig, ax = plt.subplots() -countries = ['Brazil', 'China', 'Argentina'] -title = 'Brazil, China, Argentina \n Domestic credit to private sector by banks (% of GDP)' +countries = ['China', 'Argentina'] +title = 'China, Argentina \n Inflation, consumer prices (annual %)' ax = plot_comparison(cpi, countries, title, ylabel, 0.05, ax, g_params, b_params, t_params) ``` From d0e395d6c7caea2743dfc95b0e549736ba1be359 Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Thu, 2 Mar 2023 23:46:22 +1100 Subject: [PATCH 5/8] add business cycle --- {in-work => lectures}/ business_cycle.md | 165 ++++++++++++++++------- lectures/_toc.yml | 1 + 2 files changed, 115 insertions(+), 51 deletions(-) rename {in-work => lectures}/ business_cycle.md (73%) diff --git a/in-work/ business_cycle.md b/lectures/ business_cycle.md similarity index 73% rename from in-work/ business_cycle.md rename to lectures/ business_cycle.md index a75d3e11f..f36b2c4b5 100644 --- a/in-work/ business_cycle.md +++ b/lectures/ business_cycle.md @@ -11,21 +11,26 @@ kernelspec: name: python3 --- -```{code-cell} ipython3 -!pip install wbgapi -``` - # Business Cycle ## Overview This lecture is about illustrateing business cycles in different countries and period. -Business cycle is one of the widely studied field since the birth of economics as a subject from . +The business cycle refers to the fluctuations in economic activity over time. These fluctuations can be observed in the form of expansions, contractions, recessions, and recoveries in the economy. + +In this lecture, we will see expensions and contractions of economies from 1960s to the recent pandemic using [World Bank API](https://documents.worldbank.org/en/publication/documents-reports/api). + +In addition to what's in Anaconda, this lecture will need the following libraries to get World bank data -In this lecture, we will see expensions and contractions of economies throughout the history with an emphasise on contemprary business cycles. +```{code-cell} ipython3 +:tags: [hide-output] + +!pip install wbgapi +!pip install imfpy +``` -We use the following imports. +We use the following imports ```{code-cell} ipython3 import matplotlib.pyplot as plt @@ -33,28 +38,71 @@ import pandas as pd import numpy as np import scipy.stats as st import wbgapi as wb +from imfpy.retrievals import dots ``` +## Data Acquaisition + +We will use `wbgapi` and `imfpy` to retrieve data from the World Bank and IMF API throughout this lecture. + +So let's explore how to query data together. + +We can use `wb.series.info` with parameter `q` to query available data from the World Bank (`imfpy. searches.database_codes()` in `imfpy`) + +For example, GDP growth is a key indicator to show the expension and contraction of level of economic activities. + +Let's retrive GDP growth data together + ```{code-cell} ipython3 wb.series.info(q='GDP growth') ``` +In a similar fashion, we can also retrieve data that covers different aspects of economic activities. + +We can cover indicators of + +- labour market + ```{code-cell} ipython3 +:tags: [hide-output] + wb.series.info(q='unemployment') ``` +- credit level + ```{code-cell} ipython3 +:tags: [hide-output] + wb.series.info(q='credit') ``` +- consumer price index + ```{code-cell} ipython3 +:tags: [hide-output] + wb.series.info(q='consumer') ``` +- consumption level + ```{code-cell} ipython3 +:tags: [hide-output] + wb.series.info(q='consumption') ``` +```{code-cell} ipython3 +wb.series.info(q='capital account') # TODO: Check if it is to be plotted +``` + +- international trade volumn + ++++ + +These indicators will give us an overview of variations in economic activities across time. + ## GDP Growth Rate and Unemployment First we look at the GDP growth rate and unemployment rate. @@ -116,35 +164,6 @@ title = 'Brazil, China, Argentina (GDP Growth Rate %)' ax = plot_comparison(gdp_growth.loc[countries, 1962:], countries, title, ylabel, 0.1, ax, g_params, b_params, t_params) ``` -```{code-cell} ipython3 -def plot_comparison_NBER(data, countries, title, ylabel, title_pos, ax, g_params, b_params, t_params): - for country in countries: - ax.plot(data.loc[country], label=country, **g_params) - ax.axvspan(1969, 1970, **b_params) - ax.axvspan(1973, 1975, **b_params) - ax.axvspan(1980.25, 1980.75, **b_params) - ax.axvspan(1981, 1982, **b_params) - ax.axvspan(1990, 1991, **b_params) - ax.axvspan(2001.25, 2002, **b_params) - ax.axvspan(2007, 2009, **b_params) - ax.axvspan(2020, 2020, **b_params) - ylim = ax.get_ylim()[1] - ax.text(1974, ylim + ylim * title_pos, 'Oil Crisis\n(1974)', **t_params) - ax.text(1991, ylim + ylim * title_pos, '1990s recession\n(1991)', **t_params) - ax.text(2008, ylim + ylim * title_pos, 'GFC\n(2008)', **t_params) - ax.text(2020, ylim + ylim * title_pos, 'Covid-19\n(2020)', **t_params) - ax.set_title(title, pad=40) - ax.set_ylabel(ylabel) - ax.legend() - return ax - -fig, ax = plt.subplots() - -countries = ['United States'] -title = 'United States (GDP Growth Rate %)' -ax = plot_comparison_NBER(gdp_growth.loc[countries, 1962:], countries, title, ylabel, 0.1, ax, g_params, b_params, t_params) -``` - ```{code-cell} ipython3 fig, ax = plt.subplots() @@ -199,10 +218,6 @@ unempl_rate = unempl_rate.set_index('Country') unempl_rate.columns = unempl_rate.columns.str.replace('YR', '').astype(int) ``` -```{code-cell} ipython3 -unempl_rate -``` - ```{code-cell} ipython3 fig, ax = plt.subplots() @@ -252,16 +267,14 @@ title = 'El Salvador (Unemployment Rate %)' ax = plot_comparison(unempl_rate, countries, title, ylabel, 0.04, ax, g_params, b_params, t_params) ``` +## Credit Level + ```{code-cell} ipython3 private_credit = wb.data.DataFrame('FD.AST.PRVT.GD.ZS',['CHN', 'USA', 'DEU', 'BRA', 'ARG', 'GBR'], labels=True) private_credit = private_credit.set_index('Country') private_credit.columns = private_credit.columns.str.replace('YR', '').astype(int) ``` -```{code-cell} ipython3 -private_credit -``` - ```{code-cell} ipython3 fig, ax = plt.subplots() @@ -287,16 +300,14 @@ title = 'United Kingdom and China \n Domestic credit to private sector by banks ax = plot_comparison(private_credit, countries, title, ylabel, 0.05, ax, g_params, b_params, t_params) ``` +## Inflation + ```{code-cell} ipython3 cpi = wb.data.DataFrame('FP.CPI.TOTL.ZG',['CHN', 'USA', 'DEU', 'BRA', 'ARG', 'GBR'], labels=True) cpi = cpi.set_index('Country') cpi.columns = cpi.columns.str.replace('YR', '').astype(int) ``` -```{code-cell} ipython3 -cpi -``` - ```{code-cell} ipython3 fig, ax = plt.subplots() @@ -306,10 +317,62 @@ ylabel = 'annual %' ax = plot_comparison(cpi, countries, title, ylabel, 0.05, ax, g_params, b_params, t_params) ``` +## International Trade + +```{code-cell} ipython3 +trade_us = dots('US','W00', 1960, 2020, freq='A') +trade_us['Period'] = trade_us['Period'].astype('int') +``` + ```{code-cell} ipython3 +def plot_trade(data, title, ylabel, title_pos, ax, g_params, b_params, t_params): + ax.plot(data['Period'], data['Twoway Trade'], **g_params) + ax.axvspan(1973, 1975, **b_params) + ax.axvspan(1990, 1992, **b_params) + ax.axvspan(2007, 2009, **b_params) + ax.axvspan(2019, 2021, **b_params) + ylim = ax.get_ylim()[1] + ax.text(1974, ylim + ylim * title_pos, 'Oil Crisis\n(1974)', **t_params) + ax.text(1991, ylim + ylim * title_pos, '1990s recession\n(1991)', **t_params) + ax.text(2008, ylim + ylim * title_pos, 'GFC\n(2008)', **t_params) + ax.text(2020, ylim + ylim * title_pos, 'Covid-19\n(2020)', **t_params) + ax.set_title(title, pad=40) + ax.set_ylabel(ylabel) + return ax + + fig, ax = plt.subplots() +title = 'United States International Trade Volumn' +ylabel = 'US Dollars, Millions' +plot_UStrade = plot_trade(trade_us[['Period', 'Twoway Trade']], title, ylabel, 0.05, ax, g_params, b_params, t_params) +``` -countries = ['China', 'Argentina'] -title = 'China, Argentina \n Inflation, consumer prices (annual %)' -ax = plot_comparison(cpi, countries, title, ylabel, 0.05, ax, g_params, b_params, t_params) +```{code-cell} ipython3 +fig, ax = plt.subplots() +trade_cn = dots('CN','W00', 1960, 2020, freq='A') + +trade_cn['Period'] = trade_cn['Period'].astype('int') +title = 'United States (International Trade Volumn)' +ylabel = 'US Dollars, Millions' +plot_trade_cn = plot_trade(trade_cn[['Period', 'Twoway Trade']], title, ylabel, 0.05, ax, g_params, b_params, t_params) +``` + +```{code-cell} ipython3 +fig, ax = plt.subplots() +trade_mx = dots('MX','W00', 1960, 2020, freq='A') + +trade_mx['Period'] = trade_mx['Period'].astype('int') +title = 'Mexico (International Trade Volumn)' +ylabel = 'US Dollars, Millions' +plot_trade_mx = plot_trade(trade_mx[['Period', 'Twoway Trade']], title, ylabel, 0.05, ax, g_params, b_params, t_params) +``` + +```{code-cell} ipython3 +fig, ax = plt.subplots() +trade_ar = dots('AR','W00', 1960, 2020, freq='A') + +trade_ar['Period'] = trade_ar['Period'].astype('int') +title = 'Argentina (International Trade Volumn)' +ylabel = 'US Dollars, Millions' +plot_trade_ar = plot_trade(trade_ar[['Period', 'Twoway Trade']], title, ylabel, 0.05, ax, g_params, b_params, t_params) ``` diff --git a/lectures/_toc.yml b/lectures/_toc.yml index 980833827..f826fbe0b 100644 --- a/lectures/_toc.yml +++ b/lectures/_toc.yml @@ -6,6 +6,7 @@ parts: chapters: - file: about - file: long_run_growth + - file: business_cycle - file: inequality - caption: Tools & Techniques numbered: true From c5f45151b4163f5e92b0677c6091ab2b1c25d173 Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Thu, 2 Mar 2023 23:47:32 +1100 Subject: [PATCH 6/8] move back to in work --- {lectures => in-work}/ business_cycle.md | 0 lectures/_toc.yml | 1 - 2 files changed, 1 deletion(-) rename {lectures => in-work}/ business_cycle.md (100%) diff --git a/lectures/ business_cycle.md b/in-work/ business_cycle.md similarity index 100% rename from lectures/ business_cycle.md rename to in-work/ business_cycle.md diff --git a/lectures/_toc.yml b/lectures/_toc.yml index f826fbe0b..980833827 100644 --- a/lectures/_toc.yml +++ b/lectures/_toc.yml @@ -6,7 +6,6 @@ parts: chapters: - file: about - file: long_run_growth - - file: business_cycle - file: inequality - caption: Tools & Techniques numbered: true From 9ed4888d51a9020129de591c35e52604e4232dd1 Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Thu, 2 Mar 2023 23:48:47 +1100 Subject: [PATCH 7/8] change to on push --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1dc38c8b4..e85a2f484 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,5 @@ name: Build HTML [using jupyter-book] -on: [pull_request] +on: [push] jobs: tests: runs-on: ubuntu-latest From 180b99f3725cc46ff59e154cf3ec16b7e2747ad3 Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Thu, 2 Mar 2023 23:51:53 +1100 Subject: [PATCH 8/8] add a missing bracket --- in-work/ business_cycle.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/in-work/ business_cycle.md b/in-work/ business_cycle.md index f36b2c4b5..70fa5cc1d 100644 --- a/in-work/ business_cycle.md +++ b/in-work/ business_cycle.md @@ -342,7 +342,7 @@ def plot_trade(data, title, ylabel, title_pos, ax, g_params, b_params, t_params) fig, ax = plt.subplots() -title = 'United States International Trade Volumn' +title = 'United States (International Trade Volumn)' ylabel = 'US Dollars, Millions' plot_UStrade = plot_trade(trade_us[['Period', 'Twoway Trade']], title, ylabel, 0.05, ax, g_params, b_params, t_params) ``` @@ -352,7 +352,7 @@ fig, ax = plt.subplots() trade_cn = dots('CN','W00', 1960, 2020, freq='A') trade_cn['Period'] = trade_cn['Period'].astype('int') -title = 'United States (International Trade Volumn)' +title = 'China (International Trade Volumn)' ylabel = 'US Dollars, Millions' plot_trade_cn = plot_trade(trade_cn[['Period', 'Twoway Trade']], title, ylabel, 0.05, ax, g_params, b_params, t_params) ```