Factors that contribute to economic growth of a country
Import libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.express as px
import plotly.graph_objects as go
#chart_studio.tools.set_credentials_file(username='econdata777', api_key='ADDhere')
import statsmodels.api as sm
import statsmodels.formula.api as smf
import warnings
#warnings.filterwarnings('ignore')
Import data
df1 = pd.read_csv("https://raw.githubusercontent.com/quarcs-lab/mendez2020-convergence-clubs-code-data/master/assets/dat.csv")
#df1 = pd.read_csv("https://raw.githubusercontent.com/quarcs-lab/mendez2020-convergence-clubs-code-data/master/assets/dat.csv", parse_dates =['year'])
df1
df1.head()
df1.columns
Definitions
# Import definitions of dataset
df1_def = pd.read_csv("https://raw.githubusercontent.com/quarcs-lab/mendez2020-convergence-clubs-code-data/master//assets/dat-definitions.csv")
df1_def
Descriptive statistics
df1.describe().round(2)
Data preparation
How to select data?
#df1.GDPpc
#df2 = df1[['country', 'year', 'GDPpc', 'h', 'ky', 'TFP']]
#df2
How to query data?
#df_2014 = df1[['country', 'region', 'hi1990', 'year', 'GDPpc', 'h', 'ky', 'TFP']].query("year == 2014")
#df_2014
Let's look at data of Asia in 2000 and 2014 specifically.
df_2000 = df1.query("year == 2000 and region ==['Asia']")
df_2000
df_2014 = df1.query("year == 2014 and region ==['Asia']")
df_2014
df_thailand = df1[['country', 'year', 'GDPpc', 'pop','K','lp','s', 'h', 'kp']].query("country == 'Thailand'")
df_thailand
df1[['country', 'year', 'h']].query("country==['Japan', 'China','Bolivia'] and year == 2014")
# Define the logical condictions
is_Asia = df1['region'] == 'Asia'
is_HighIncome = df1['hi1990'] == 'yes'
is_1990 = df1['year'] == 1990
# Apply the logical conditions
df1[is_Asia & is_HighIncome & is_1990]
Data visualization
The trend of world's GDP per capita
px.choropleth(
df1,
locations="isocode",
color="GDPpc",
hover_name="country",
animation_frame="year",
color_continuous_scale='sunset',
projection="natural earth",title="World's GDP per capita",
labels={"GDPpc": "GDP per capita"})
px.bar(df1, x = 'hi1990', color= 'country', title="High income countries")
Factors that contribute to economic growth of each country.
Education
px.scatter(
df1,
x="log_GDPpc",
y="s",
color="region",
size="pop", size_max=40,
hover_name="country",
labels=dict(log_GDPpc="GDP per capita in log",
s="Years of Schooling",
region="Continent",
pop= "Population"),
animation_frame="year",
animation_group="country",
title="Does education affect country's economic growth?"
)
To get a clearer picture, let's look at each region specifically.
px.scatter(
df1,
x="log_GDPpc",
y="s",
color="region",
size="pop", size_max=60,
trendline="ols",
hover_name="country",
facet_col="region",
animation_frame="year",
facet_col_wrap=2,
height=800,
template="simple_white",
title="The relationship between education and GDP per capita in each region"
)
Now, let see the differences in high income countries and others.
px.scatter(
df1,
x="log_GDPpc",
y="s",
color="hi1990",
hover_name="country",
animation_frame = 'year',
trendline="ols",
title="How education affect economic growth of high-income countries and other countries.")
Let's take a closer look in Asia.
px.scatter(
df1.query('region==["Asia"]'),
x="log_GDPpc",
y="s",
size ="pop", size_max=60,
hover_name="country",
color="country",
animation_frame= 'year',
template="simple_white",
trendline_scope="overall",
labels=dict(log_GDPpc="GDP per capita in log",
s="Years of Schooling",
pop= "Population"),
title="Looking at Asia, does education lead to economic growth?"
)
Let's compare countries!
px.scatter(
df1.query(
'country == ["Thailand","Vietnam", "Ghana","Kenya", "United States","Mexico", "France", "Germany", "Australia", "New Zealand"]'
),
x="log_GDPpc",
y="s",
color="country",
size="pop",
size_max=60,
trendline="ols",
hover_name="country",
facet_col="region",
animation_frame="year",
width=900,
title="The relationship between education and GDP per capita in ten countries",
)
Labor productivity
Can labor productivity affect economic growth of the country?
px.box(
df1,
x="log_lp",
color="region",
hover_name="country",
animation_frame="year",
title="The changing trend of labor productivity",
labels=dict(log_lp="Labor productivity in log",)
)
px.scatter(
df1,
x="log_GDPpc",
y="log_lp",
hover_name="country",
color="region",
animation_frame= 'year',
template="simple_white",
title="Does labor productivity contribute to economic growth?",
labels=dict(log_lp="Labor productivity in log",
log_GDPpc="GDP per capita in log")
)
Does labor productivity affect economic growth?
px.scatter(
df1,
x="log_GDPpc",
y="log_lp",
color="country",
facet_col="region",
facet_col_wrap=2,
height=800,
animation_frame='year',
title='The relationship between labor productivity and GDP per capita in each region'
)
I, now, distinguish between high income countries and other countries.
px.scatter(
df1,
x="log_GDPpc",
y="log_lp",
color="region",
size="pop", size_max=60,
trendline="ols",
hover_name="country",
facet_col="hi1990",
animation_frame="year",
title="GDP per capita and labor productivity in high income countries and other countries",
labels=dict(log_lp="Labor productivity in log",
log_GDPpc="GDP per capita in log")
)
Let's compare Asia and Europe.
px.line(
df1.query("region==['Asia', 'Europe']"),
x="year",
y="log_lp",
color="region",
hover_name="country",
labels=dict(log_lp="Labor productivity in log"),
title="Comparison of labor productivity between Europe and Asia"
)
What drives labor productivity?
px.scatter(
df1,
y="log_lp",
x="log_h",
log_x=False,
color="region",
size="pop",
size_max=60,
hover_name="country",
height=500,
width=800,
template="simple_white",
color_discrete_sequence=px.colors.qualitative.G10,
animation_frame="year",
title="Is human capital important to labor productivity?",
labels=dict(
region="Continent",
pop="Population",
log_lp="Labor productivity in log",
log_h="Human capital index in log",
),
)
Human capital
Is human capital important to economic growth?
px.choropleth(
df1,
locations="isocode",
color="h",
hover_name="country",
animation_frame="year",
color_continuous_scale='plasma',
projection="natural earth",title="World's human capital index",
labels={"h": "Human capital index"})
px.scatter(
df1,
x="log_GDPpc",
y="log_h",
color="region",
size="pop", size_max=40,
trendline="ols",
hover_name="country",
facet_col="hi1990",
animation_frame="year",
template="simple_white",
labels=dict(log_GDPpc="GDP per capita in log", log_h="Human capital index in log"),
title="Relationship between GDP per capita and human capital index"
)
px.scatter(
df1,
x="log_GDPpc",
y="log_h",
color="country",
facet_col="region",
facet_col_wrap=2,
height=800,
animation_frame='year',
title='The relationship between human capital index and GDP per capita in each region',
)
Let's take a closer look at some ASEAN countries.
px.scatter(
df1.query('country == ["Thailand","Vietnam", "Brunei","Indonesia", "Laos","Malaysia", "Myanmar", "Philippines", "Singapore"]'
),
y="log_h",
x="log_GDPpc",
log_x=False,
color="country",
size="pop",
size_max=60,
hover_name="country",
height=500,
width=800,
template="simple_white",
animation_frame="year",
color_discrete_sequence=px.colors.qualitative.G10,
title = "Looking at ASEAN countries, does human capital correlate with GDP per capita?",
labels=dict(
region="Continent",
pop="Population",
log_GDPpc="GDP per capita in log",
log_h="Human capital index in log"))
Population
px.treemap(
df1.query("year == 2000"),
path=[px.Constant("World"), "region", "country"],
values="pop",
color="GDPpc",
hover_data=["isocode"],
color_continuous_scale="RdBu",
color_continuous_midpoint=np.average(df1["GDPpc"], weights=df1["pop"]),
title='Size of the population and GDP per capita in 2000'
)
px.treemap(
df1.query("year == 2014"),
path=[px.Constant("World"), "region", "country"],
values="pop",
color="GDPpc",
hover_data=["isocode"],
color_continuous_scale="RdBu",
color_continuous_midpoint=np.average(df1["GDPpc"], weights=df1["pop"]),
title='Size of the population and GDP per capita in 2014'
)