Introduction
Methodology and data
Beta convergence
Inequality
Data
Import data
df=pd.read_csv('/work/Dataf.csv')
df.round(2)
df1=pd.read_csv('/work/Datap.csv')
df1.round(2)
df2 =pd.read_csv('/work/test.csv')
Explore data
df[['lnlp_2011', 'glp', 'lnhk', 'ks']].describe().round(2)
Tree plot
px.treemap(df1,
color = 'lnlp',
values = "LAB",
path = ["Province", "City"],
hover_name = "City",
color_continuous_scale='jet')
Box plot
px.box(
df1,
x="lnlp",
color="Province",
hover_name= 'City',
range_x = [9, 13],
animation_frame = 'year'
)
Beta convergence
y= df["glp"]
x1= df["lnlp_2011"]
l= df["L_2011"]
k= df["K_2011"]
Whole cities convergence
px.scatter(
df,
x="lnlp_2011",
y="glp",
hover_name="City",
#color="country",
trendline="ols",
marginal_x="rug",
marginal_y="rug",
labels={"ln_gdp_2011": "Log LP in 2011",
"g2011-2020": "Growth of LP in 2011-2020"}
)
Heterogenous beta convergence
px.scatter(
df,
x="lnlp_2011",
y="glp",
hover_name="City",
color="P",
trendline="ols",
marginal_x="rug",
marginal_y="rug",
labels={"ln_gdp_2011": "Log GDPpc in 2011",
"g2011-2020": "Growth GDPpc 2011-2020"}
)
Regional inequality
Coefficient of variation and Theils index
pclp_wide = pd.pivot_table(df1, values='lp', index = 'City', columns='year').dropna()
from scipy import stats
cv = pclp_wide.apply(stats.variation, axis = 0)
theil = pclp_wide.apply(lambda x: inequality.theil.Theil(x).T, axis=0)
df = pd.DataFrame({'year':range(2011, 2021,1),
'CV': cv,
'theil': theil})
df.set_index('year').plot();
plt.xticks(range(2011, 2021,2))
plt.show()
Lorenz Curve
# Function to plot Lorenz Curve
timespan = [str(i) for i in range(2011,2021,1)]
fig, ax = plt.subplots()
plt.close()
def animate(y):
fig, ax = plt.subplots(figsize=(6,6))
f_vals, l_vals = qe.lorenz_curve(df2[y].values)
ax.set_aspect(1.0) #sets the height to width ratio to 1.5.
ax.plot(f_vals, l_vals, label='LC, Per Capita LP')
ax.plot(f_vals, f_vals, label='LC, Equality')
ax.fill(f_vals, l_vals, "c")
ax.annotate('{}, G={:.4f}'.format(y, qe.gini_coefficient(df2[y].values)), xy=(0.25, 0.75))
ax.legend()
plt.show()
# Plotting the Lorenc Curve for each year
from IPython.display import clear_output
import matplotlib.pyplot as plt
from time import sleep
plt.rcParams['font.size'] = '16'
for i in timespan:
animate(i)
sleep(0.5)
clear_output(wait=True)