Skip to content

Commit 1c587e3

Browse files
committed
updates
1 parent edb76c6 commit 1c587e3

File tree

2 files changed

+47
-41
lines changed

2 files changed

+47
-41
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.8257332034366347,0.44248654139458754,0.5342948198773423
3-
1953,0.8059487586599338,0.42645440609359486,0.5158978980963697
4-
1956,0.8121790488050631,0.4442694287339931,0.5349293526208138
5-
1959,0.7952068741637922,0.43749348077061523,0.5213985948309406
6-
1962,0.808694507657936,0.4435843103853638,0.5345127915054347
7-
1965,0.7904149225687935,0.43763715466663455,0.7487860020887751
8-
1968,0.7982885066993515,0.4208620794438898,0.5242396427381535
9-
1971,0.7911574835420261,0.42333442460902587,0.5576454812313479
10-
1977,0.7571418922185222,0.46187678800902643,0.5704448110072055
11-
1983,0.7494335400643035,0.43934561846447007,0.5662220844385907
12-
1989,0.7715705301674298,0.5115249581654171,0.6013995687471435
13-
1992,0.75081266140553,0.47406506720767927,0.5983592657979551
14-
1995,0.756949238811024,0.4896552355840093,0.5969779516716919
15-
1998,0.7603291991801191,0.49117441585168625,0.5774462841723321
16-
2001,0.7816118750507045,0.5239092994681127,0.6042739644967284
17-
2004,0.7700355469522353,0.48843503839032515,0.598143220179272
18-
2007,0.782141377648697,0.5197156312086194,0.6263452195753192
19-
2010,0.825082529519343,0.5195972120145608,0.6453653328291911
20-
2013,0.8227698931835298,0.5314001749843348,0.649868291777264
21-
2016,0.8342975903562216,0.5541400068900835,0.6706846793375284
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

lectures/inequality.md

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ We will need to install the following packages
6565

6666
```{code-cell} ipython3
6767
:tags: [hide-output]
68+
6869
!pip install wbgapi
6970
```
7071

@@ -298,12 +299,10 @@ mystnb:
298299
alt: lorenz_us
299300
---
300301
fig, ax = plt.subplots()
301-
302302
ax.plot(f_vals_nw[-1], l_vals_nw[-1], label=f'net wealth')
303303
ax.plot(f_vals_ti[-1], l_vals_ti[-1], label=f'total income')
304304
ax.plot(f_vals_li[-1], l_vals_li[-1], label=f'labor income')
305305
ax.plot(f_vals_nw[-1], f_vals_nw[-1], label=f'equality')
306-
307306
ax.legend()
308307
plt.show()
309308
```
@@ -346,6 +345,14 @@ The Gini coefficient is closely related to the Lorenz curve.
346345
In fact, it can be shown that its value is twice the area between the line of
347346
equality and the Lorenz curve (e.g., the shaded area in the following Figure below).
348347
348+
```{note}
349+
Another way to think of the gini coefficient is the area between the 45-degree line of
350+
perfect equality and the Lorenz curve minus the area below the Lorenz curve devided by
351+
the total area below the 45-degree line.
352+
353+
In other words, it is a measure of average deviation from the line of equality.
354+
```
355+
349356
The idea is that $G=0$ indicates complete equality, while $G=1$ indicates complete inequality.
350357
351358
```{code-cell} ipython3
@@ -478,7 +485,7 @@ coefficient.
478485
479486
Now let's look at Gini coefficients for US data.
480487
481-
In this section we will get Gini coefficients from the World Bank using the [wbgapi](https://blogs.worldbank.org/opendata/introducing-wbgapi-new-python-package-accessing-world-bank-data).
488+
In this section we will get pre-computed Gini coefficients from the World Bank using the [wbgapi](https://blogs.worldbank.org/opendata/introducing-wbgapi-new-python-package-accessing-world-bank-data).
482489
483490
Let's search the world bank data for gini to find the Series ID.
484491
@@ -502,7 +509,7 @@ data = wb.data.DataFrame("SI.POV.GINI", "USA")
502509
data
503510
```
504511
505-
```{note}
512+
```{tip}
506513
This package often returns data with year information contained in the columns. This is not always convenient for simple plotting with pandas so it can be useful to transpose the results before plotting
507514
```
508515
@@ -518,9 +525,9 @@ ax.set_ylim(0,data_usa.max()+5)
518525
plt.show()
519526
```
520527
521-
The gini coefficient does not have significant variation in the full range from 0 to 100.
528+
The gini coefficient is relatively slow moving and does not have significant variation in the full range from 0 to 100.
522529
523-
In fact we can take a quick look across all countries and all years in the world bank dataset to observe this.
530+
Using `pandas` we can take a quick look across all countries and all years in the world bank dataset to understand how the Gini coefficient varies across countries and time.
524531
525532
```{code-cell} ipython3
526533
gini_all = wb.data.DataFrame("SI.POV.GINI")
@@ -535,7 +542,7 @@ gini_all = gini_all.unstack(level='economy').dropna()
535542
gini_all.plot(kind="hist", title="Gini coefficient");
536543
```
537544
538-
Therefore we can see that across 50 years of data and all countries the measure only varies between 20 and 65.
545+
Therefore we can see that across 50 years of data and all countries (including low and high income countries) the measure only varies between 20 and 65.
539546
540547
This variation would be even smaller for the subset of wealthy countries, so let us zoom in a little on the US data and add some trendlines.
541548
@@ -582,18 +589,20 @@ plt.show()
582589
583590
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).
584591
585-
```{admonition} TODO
586-
Why did GINI fall in 2020? I would have thought it accelerate in the other direction or was there a lag in investment returns around COVID
587-
```
588-
589592
## Comparing income and wealth inequality (the US case)
590593
594+
The Gini coefficient can also be computed over different distributions such as *income* and *wealth*.
595+
591596
We can use the data collected above {ref}`survey of consumer finances <data:survey-consumer-finance>` to look at the gini coefficient when using income when compared to wealth data.
592597
593-
Let's compute the gin coefficient for net wealth, total income, and labour income.
598+
Let's compute the gin coefficient for net wealth, total income, and labour income for the most recent year in our sample.
594599
595600
This section makes use of the following code to compute the data, however to speed up execution we have pre-compiled the results and will use that in the subsequent analysis.
596601
602+
```{code-cell} ipython3
603+
df_income_wealth.year.describe()
604+
```
605+
597606
```{code-cell} ipython3
598607
:tags: [skip-execution, hide-input, hide-output]
599608
@@ -631,6 +640,10 @@ results = pd.DataFrame(results, index=years)
631640
results.to_csv("_static/lecture_specific/inequality/usa-gini-nwealth-tincome-lincome.csv", index_label='year')
632641
```
633642
643+
While the data can be computed using the code above, we will import a pre-computed dataset from the lecture repository.
644+
645+
<!-- TODO: update from csv to github location -->
646+
634647
```{code-cell} ipython3
635648
ginis = pd.read_csv("_static/lecture_specific/inequality/usa-gini-nwealth-tincome-lincome.csv", index_col='year')
636649
ginis.head(n=5)
@@ -926,20 +939,13 @@ Plot the top shares generated from Lorenz curve and the top shares approximated
926939
:class: dropdown
927940
```
928941
929-
We will use the `interpolation` package in this solution.
930-
931-
```{code-cell} ipython3
932-
:tags: [hide-output]
933-
934-
!pip install --upgrade interpolation
935-
from interpolation import interp
936-
```
942+
+++
937943
938944
Here is one solution:
939945
940946
```{code-cell} ipython3
941947
def lorenz2top(f_val, l_val, p=0.1):
942-
t = lambda x: interp(f_val, l_val, x)
948+
t = lambda x: np.interp(x, f_val, l_val)
943949
return 1- t(1 - p)
944950
```
945951

0 commit comments

Comments
 (0)