Skip to content

Commit

Permalink
Compare inquality across countries
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcky committed Mar 8, 2024
1 parent 1c587e3 commit d16e570
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
year,n_wealth,t_income,l_income
1950,0.8257332034366358,0.4424865413945875,0.5342948198773428
1953,0.8059487586599331,0.42645440609359453,0.5158978980963707
1956,0.8121790488050629,0.4442694287339922,0.5349293526208139
1959,0.7952068741637917,0.43749348077061556,0.5213985948309421
1962,0.8086945076579354,0.4435843103853641,0.5345127915054346
1965,0.790414922568793,0.4376371546666345,0.7487860020887755
1968,0.7982885066993517,0.42086207944388987,0.524239642738153
1971,0.7911574835420266,0.4233344246090252,0.5576454812313467
1977,0.7571418922185217,0.46187678800902604,0.5704448110072053
1983,0.7494335400643017,0.4393456184644693,0.5662220844385908
1989,0.7715705301674308,0.5115249581654219,0.6013995687471431
1992,0.7508126614055308,0.47406506720767694,0.5983592657979548
1995,0.756949238811026,0.48965523558400526,0.5969779516716914
1998,0.7603291991801175,0.4911744158516885,0.5774462841723366
2001,0.7816118750507022,0.523909299468113,0.6042739644967348
2004,0.770035546952236,0.48843503839032615,0.5981432201792747
2007,0.7821413776486992,0.5197156312086196,0.6263452195753294
2010,0.8250825295193438,0.51959721201456,0.6453653328291932
2013,0.8227698931835281,0.5314001749843356,0.6498682917772638
2016,0.8342975903562243,0.5541400068900844,0.6706846793375284
1950,0.8257332034366359,0.44248654139458704,0.5342948198773421
1953,0.8059487586599332,0.42645440609359414,0.5158978980963693
1956,0.8121790488050623,0.4442694287339929,0.5349293526208143
1959,0.7952068741637921,0.4374934807706162,0.5213985948309414
1962,0.8086945076579385,0.4435843103853643,0.5345127915054336
1965,0.7904149225687938,0.4376371546666339,0.748786002088776
1968,0.7982885066993525,0.4208620794438893,0.5242396427381537
1971,0.7911574835420264,0.4233344246090261,0.5576454812313487
1977,0.7571418922185211,0.46187678800902404,0.5704448110072055
1983,0.7494335400643021,0.43934561846446935,0.5662220844385908
1989,0.7715705301674326,0.5115249581654199,0.6013995687471441
1992,0.75081266140553,0.47406506720767994,0.5983592657979562
1995,0.7569492388110272,0.48965523558400526,0.596977951671689
1998,0.7603291991801175,0.49117441585168564,0.5774462841723361
2001,0.7816118750507013,0.5239092994681116,0.6042739644967291
2004,0.7700355469522365,0.4884350383903243,0.5981432201792726
2007,0.7821413776486991,0.5197156312086196,0.6263452195753233
2010,0.8250825295193426,0.5195972120145639,0.6453653328291923
2013,0.8227698931835287,0.5314001749843371,0.6498682917772659
2016,0.8342975903562232,0.5541400068900836,0.6706846793375284
80 changes: 79 additions & 1 deletion lectures/inequality.md
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ plt.show()
Looking at this graph you can see that inequality was falling in the USA until 1981 when it appears to have started to change course and steadily rise over time (growing inequality).
## Comparing income and wealth inequality (the US case)
### Comparing income and wealth inequality (the US case)
The Gini coefficient can also be computed over different distributions such as *income* and *wealth*.
Expand Down Expand Up @@ -716,6 +716,84 @@ substantially since 1980.
The wealth time series exhibits a strong U-shape.
+++
### Cross-country comparisons of income inequality
As we saw earlier in this lecture we used `wbgapi` to get gini data across many countries and saved it in a variable called `gini_all`
In this section we will compare a few countries and the evolution in their respective gini coefficients
```{code-cell} ipython3
# Obtain data for all countries as a table
data = gini_all.unstack()
```
```{code-cell} ipython3
data.columns
```
There are 167 countries represented in this dataset.
Let us compare three western economies: USA, United Kingdom, and Norway
```{code-cell} ipython3
data[['USA','GBR', 'NOR']].plot(ylabel='gini coefficient')
```
From this plot we can observe that the USA has a higher gini coefficient (i.e. higher income inequality) when compared to the UK and Norway.
Norway has the lowest gini coefficient over the three economies from the year 2003, and it is substantially lower than the USA suggesting the Lorenz curve is much closer to the 45-degree line of equality.
+++
### (Optional) Gini Coefficient and GDP per capita (over time)
```{code-cell} ipython3
countries = ['USA', 'NOR', 'GBR']
```
```{code-cell} ipython3
gdppc = wb.data.DataFrame("NY.GDP.PCAP.KD", countries).T
```
Let's rearrange the data so that we can plot gdp per capita and the gini coefficient across years
```{code-cell} ipython3
pdata = pd.DataFrame(data[countries].unstack())
pdata.index.names = ['country', 'year']
pdata.columns = ['gini']
```
```{code-cell} ipython3
pdata
```
```{code-cell} ipython3
pgdppc = pd.DataFrame(gdppc.unstack())
pgdppc.index.names = ['country', 'year']
pgdppc.columns = ['gdppc']
```
```{code-cell} ipython3
plot_data = pdata.merge(pgdppc, left_index=True, right_index=True)
```
```{code-cell} ipython3
plot_data.reset_index(inplace=True)
```
```{code-cell} ipython3
plot_data.year = plot_data.year.map(lambda x: int(x.replace('YR','')))
```
```{code-cell} ipython3
import plotly.express as px
fig = px.line(plot_data, x="gini", y="gdppc", color="country", text="year", height=800)
fig.update_traces(textposition="bottom right")
fig.show()
```
## Top shares
Another popular measure of inequality is the top shares.
Expand Down

0 comments on commit d16e570

Please sign in to comment.