# Install libraries
#!pip install --upgrade pip --quiet
#!pip install statsmodels --quiet
!pip install linearmodels --quiet
!pip install statsmodels --upgrade
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style('darkgrid')
sns.set_context('paper', font_scale= 1.3)
import statsmodels.formula.api as smf
import statsmodels.api as sm
import statsmodels.base.model as smclass
import linearmodels as plm
import plotly.express as px
df: PWT 10.0
# import data
#df = pd.read_csv("https://raw.githubusercontent.com/quarcs-lab/mendez2020-convergence-clubs-code-data/master/assets/dat.csv")
df = pd.read_stata("https://www.rug.nl/ggdc/docs/pwt100.dta")
df
df_2019log: Determinants of growth 2019 (log form)
df_2019log = df1.query('year == 2019').loc[:, ['country', 'year','y', 'k','hc','a']]
df_2019log
df2: Wide panel for labour productivity
# Pivot panel data from long form to wide form
df2 = df1.pivot_table(
index=['country','region'],
columns='year',
values='y').reset_index(drop=False)
# Make sure the column names are strings
df2.columns = df2.columns.astype(str)
df2
df3: Wide panel for ratio of physical capital
# Pivot panel data from long form to wide form
df3 = df1.pivot_table(
index=['country', 'region'],
columns='year',
values='k').reset_index(drop=False)
# Make sure the column names are strings
df3.columns = df3.columns.astype(str)
df3
df4: Wide panel for human capital
# Pivot panel data from long form to wide form
df4 = df1.pivot_table(
index=['country', 'region'],
columns='year',
values='h').reset_index(drop=False)
# Make sure the column names are strings
df4.columns = df4.columns.astype(str)
df4
df5: Wide panel for TFP
df5 = df1.pivot_table(
index=['country', 'region'],
columns='year',
values='a').reset_index(drop=False)
# Make sure the column names are strings
df5.columns = df5.columns.astype(str)
df5
# descriptive statistics for per capita GDP
df2.describe().round(2)
# descriptive statistics for the ratio physical capital to output
df3.describe().round(2)
Evolution of disparities
Sigma convergence: labour productivity (1970-2019)
df2c = df2_drop.loc[:,'1970':'2019'].values
years3 = np.arange(1970,2020)
years3
sigma_df2c = df2c.std(axis=0)
plt.plot(years3, sigma_df2c)
plt.title("Sigma Convergence in (log) labour productivity (1970-2019)")
plt.ylabel('Stand. Dev.of log labour productivity');
Beta convergence: labour productivity (1970-2019)
df2_drop['g1970_2019'] = df2_drop['2019']-df2_drop['1970']
sns.lmplot(x="1970", y="g1970_2019", data=df2_drop);
px.scatter(
df2_drop,
x="1970",
y="g1970_2019",
hover_name="country",
color="region",
trendline="ols",
marginal_x="box",
marginal_y="box")
Beta convergence: labour productivity (1970-1990)
sns.lmplot(x="1970", y="g1970_1990", hue='region', ci=None, data=df2_drop);
px.scatter(
df2_drop,
x="1970",
y="g1970_1990",
hover_name="country",
color="region",
trendline="ols",
marginal_x="box",
marginal_y="box")
Beta convergence: Labour productivity (1990-2019)
px.scatter(
df2_drop,
x="1990",
y="g1990_2019",
hover_name="country",
color="region",
trendline="ols",
marginal_x="box",
marginal_y="box")
Beta convergence: Physical capital ratio (1970-2019)
df3_drop['g1970_2019'] = df3_drop['2019']-df3_drop['1970']
sns.lmplot(x="1970", y="g1970_2019", data=df3_drop);
sns.lmplot(x="1970", y="g1970_2019", hue='region', ci=None, data=df3_drop);
Results of Beta convergence
log labour productivity
1970-2019
y = df2_drop['g1970_2019']
X = df2_drop['1970']
X_withconst = sm.add_constant(X)
OLS = sm.OLS(y, X_withconst).fit()
print(OLS.summary())