Skip to content

Commit d16e570

Browse files
committed
Compare inquality across countries
1 parent 1c587e3 commit d16e570

File tree

2 files changed

+99
-21
lines changed

2 files changed

+99
-21
lines changed
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
year,n_wealth,t_income,l_income
2-
1950,0.8257332034366358,0.4424865413945875,0.5342948198773428
3-
1953,0.8059487586599331,0.42645440609359453,0.5158978980963707
4-
1956,0.8121790488050629,0.4442694287339922,0.5349293526208139
5-
1959,0.7952068741637917,0.43749348077061556,0.5213985948309421
6-
1962,0.8086945076579354,0.4435843103853641,0.5345127915054346
7-
1965,0.790414922568793,0.4376371546666345,0.7487860020887755
8-
1968,0.7982885066993517,0.42086207944388987,0.524239642738153
9-
1971,0.7911574835420266,0.4233344246090252,0.5576454812313467
10-
1977,0.7571418922185217,0.46187678800902604,0.5704448110072053
11-
1983,0.7494335400643017,0.4393456184644693,0.5662220844385908
12-
1989,0.7715705301674308,0.5115249581654219,0.6013995687471431
13-
1992,0.7508126614055308,0.47406506720767694,0.5983592657979548
14-
1995,0.756949238811026,0.48965523558400526,0.5969779516716914
15-
1998,0.7603291991801175,0.4911744158516885,0.5774462841723366
16-
2001,0.7816118750507022,0.523909299468113,0.6042739644967348
17-
2004,0.770035546952236,0.48843503839032615,0.5981432201792747
18-
2007,0.7821413776486992,0.5197156312086196,0.6263452195753294
19-
2010,0.8250825295193438,0.51959721201456,0.6453653328291932
20-
2013,0.8227698931835281,0.5314001749843356,0.6498682917772638
21-
2016,0.8342975903562243,0.5541400068900844,0.6706846793375284
2+
1950,0.8257332034366359,0.44248654139458704,0.5342948198773421
3+
1953,0.8059487586599332,0.42645440609359414,0.5158978980963693
4+
1956,0.8121790488050623,0.4442694287339929,0.5349293526208143
5+
1959,0.7952068741637921,0.4374934807706162,0.5213985948309414
6+
1962,0.8086945076579385,0.4435843103853643,0.5345127915054336
7+
1965,0.7904149225687938,0.4376371546666339,0.748786002088776
8+
1968,0.7982885066993525,0.4208620794438893,0.5242396427381537
9+
1971,0.7911574835420264,0.4233344246090261,0.5576454812313487
10+
1977,0.7571418922185211,0.46187678800902404,0.5704448110072055
11+
1983,0.7494335400643021,0.43934561846446935,0.5662220844385908
12+
1989,0.7715705301674326,0.5115249581654199,0.6013995687471441
13+
1992,0.75081266140553,0.47406506720767994,0.5983592657979562
14+
1995,0.7569492388110272,0.48965523558400526,0.596977951671689
15+
1998,0.7603291991801175,0.49117441585168564,0.5774462841723361
16+
2001,0.7816118750507013,0.5239092994681116,0.6042739644967291
17+
2004,0.7700355469522365,0.4884350383903243,0.5981432201792726
18+
2007,0.7821413776486991,0.5197156312086196,0.6263452195753233
19+
2010,0.8250825295193426,0.5195972120145639,0.6453653328291923
20+
2013,0.8227698931835287,0.5314001749843371,0.6498682917772659
21+
2016,0.8342975903562232,0.5541400068900836,0.6706846793375284

lectures/inequality.md

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ plt.show()
589589
590590
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).
591591
592-
## Comparing income and wealth inequality (the US case)
592+
### Comparing income and wealth inequality (the US case)
593593
594594
The Gini coefficient can also be computed over different distributions such as *income* and *wealth*.
595595
@@ -716,6 +716,84 @@ substantially since 1980.
716716
717717
The wealth time series exhibits a strong U-shape.
718718
719+
+++
720+
721+
### Cross-country comparisons of income inequality
722+
723+
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`
724+
725+
In this section we will compare a few countries and the evolution in their respective gini coefficients
726+
727+
```{code-cell} ipython3
728+
# Obtain data for all countries as a table
729+
data = gini_all.unstack()
730+
```
731+
732+
```{code-cell} ipython3
733+
data.columns
734+
```
735+
736+
There are 167 countries represented in this dataset.
737+
738+
Let us compare three western economies: USA, United Kingdom, and Norway
739+
740+
```{code-cell} ipython3
741+
data[['USA','GBR', 'NOR']].plot(ylabel='gini coefficient')
742+
```
743+
744+
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.
745+
746+
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.
747+
748+
+++
749+
750+
### (Optional) Gini Coefficient and GDP per capita (over time)
751+
752+
```{code-cell} ipython3
753+
countries = ['USA', 'NOR', 'GBR']
754+
```
755+
756+
```{code-cell} ipython3
757+
gdppc = wb.data.DataFrame("NY.GDP.PCAP.KD", countries).T
758+
```
759+
760+
Let's rearrange the data so that we can plot gdp per capita and the gini coefficient across years
761+
762+
```{code-cell} ipython3
763+
pdata = pd.DataFrame(data[countries].unstack())
764+
pdata.index.names = ['country', 'year']
765+
pdata.columns = ['gini']
766+
```
767+
768+
```{code-cell} ipython3
769+
pdata
770+
```
771+
772+
```{code-cell} ipython3
773+
pgdppc = pd.DataFrame(gdppc.unstack())
774+
pgdppc.index.names = ['country', 'year']
775+
pgdppc.columns = ['gdppc']
776+
```
777+
778+
```{code-cell} ipython3
779+
plot_data = pdata.merge(pgdppc, left_index=True, right_index=True)
780+
```
781+
782+
```{code-cell} ipython3
783+
plot_data.reset_index(inplace=True)
784+
```
785+
786+
```{code-cell} ipython3
787+
plot_data.year = plot_data.year.map(lambda x: int(x.replace('YR','')))
788+
```
789+
790+
```{code-cell} ipython3
791+
import plotly.express as px
792+
fig = px.line(plot_data, x="gini", y="gdppc", color="country", text="year", height=800)
793+
fig.update_traces(textposition="bottom right")
794+
fig.show()
795+
```
796+
719797
## Top shares
720798
721799
Another popular measure of inequality is the top shares.

0 commit comments

Comments
 (0)