You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lectures/inequality.md
+38-76Lines changed: 38 additions & 76 deletions
Original file line number
Diff line number
Diff line change
@@ -410,7 +410,7 @@ $$
410
410
It is an average measure of deviation from the line of equality.
411
411
412
412
```{seealso}
413
-
The World in Data project has a [nice graphical exploration of the Lorenz curve and the Gini coefficient](https://ourworldindata.org/what-is-the-gini-coefficient])
413
+
The World in Data project has a [nice graphical exploration of the Lorenz curve and the Gini coefficient](https://ourworldindata.org/what-is-the-gini-coefficient)
414
414
```
415
415
416
416
### Gini coefficient of simulated data
@@ -507,9 +507,9 @@ plt.show()
507
507
The plots show that inequality rises with $\sigma$, according to the Gini
508
508
coefficient.
509
509
510
-
### Gini coefficient for US data (income)
510
+
### Gini coefficient for income (US data)
511
511
512
-
Now let's look at the Gini coefficient using US data.
512
+
Let's look at the Gini coefficient for the distribution of income in the US.
513
513
514
514
We will get pre-computed Gini coefficients (based on income) from the World Bank using the [wbgapi](https://blogs.worldbank.org/opendata/introducing-wbgapi-new-python-package-accessing-world-bank-data).
515
515
@@ -523,49 +523,8 @@ We now know the series ID is `SI.POV.GINI`.
523
523
524
524
Another, and often useful way to find series ID, is to use the [World Bank data portal](https://data.worldbank.org) and then use `wbgapi` to fetch the data.
525
525
526
-
Let us fetch the data for the USA and request for it to be returned as a `DataFrame`.
**Note:** 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
536
-
537
-
```{code-cell} ipython3
538
-
data = data.T # Obtain years as rows
539
-
data_usa = data['USA'] # Series of US data
540
-
```
541
-
542
-
The `data_usa` series can now be plotted using the pandas `.plot` method.
543
-
544
-
```{code-cell} ipython3
545
-
---
546
-
mystnb:
547
-
figure:
548
-
caption: Gini coefficients (USA)
549
-
name: gini_usa1
550
-
---
551
-
fig, ax = plt.subplots()
552
-
ax = data_usa.plot(ax=ax)
553
-
ax.set_ylim(0, data_usa.max() + 5)
554
-
ax.set_ylabel("Gini coefficient")
555
-
ax.set_xlabel("year")
556
-
plt.show()
557
-
```
558
-
559
-
As can be seen in {numref}`gini_usa1` the Gini coefficient:
560
-
561
-
1. trended upward from 1980 to 2020 and then dropped slightly following the COVID pandemic
562
-
1. moves slowly over time
563
-
3. does not have significant variation in the full range from 0 to 100
564
-
565
526
Using `pandas` we can take a quick look across all countries and all years in the World Bank dataset.
566
527
567
-
By leaving off the `"USA"` this function returns all Gini data that is available.
568
-
569
528
```{code-cell} ipython3
570
529
---
571
530
mystnb:
@@ -588,43 +547,64 @@ ax.set_ylabel("frequency")
588
547
plt.show()
589
548
```
590
549
591
-
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.
550
+
We can see in {numref}`gini_histogram` that across 50 years of data and all countries
551
+
the measure only varies between 20 and 65.
592
552
593
-
{numref}`gini_usa1` suggests there is a change in trend around the year 1980.
**Note:** 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
563
+
564
+
```{code-cell} ipython3
565
+
data = data.T # Obtain years as rows
566
+
data_usa = data['USA'] # pd.Series of US data
567
+
```
594
568
595
569
Let us zoom on the US data so we can more clearly observe trends.
596
570
597
571
```{code-cell} ipython3
598
572
---
599
573
mystnb:
600
574
figure:
601
-
caption: Gini coefficients (USA)
602
-
name: gini_usa_trend
575
+
caption: Gini coefficients for income distribution (USA)
576
+
name: gini_usa1
603
577
---
604
578
fig, ax = plt.subplots()
605
579
ax = data_usa.plot(ax=ax)
606
580
ax.set_ylim(data_usa.min()-1, data_usa.max()+1)
607
-
ax.set_ylabel("Gini coefficient")
581
+
ax.set_ylabel("Gini coefficient (income)")
608
582
ax.set_xlabel("year")
609
583
plt.show()
610
584
```
611
585
612
-
{numref}`gini_usa_trend` shows inequality was falling in the USA until 1980 when it appears to have started to change course and steadily rise over time.
586
+
As can be seen in {numref}`gini_usa1` the Gini coefficient:
587
+
588
+
1. trended upward from 1980 to 2020 and then dropped slightly following at the start of the COVID pandemic
589
+
2. moves slowly over time
613
590
614
591
(compare-income-wealth-usa-over-time)=
615
-
### Comparing income and wealth inequality (the US case)
592
+
### Gini coefficient for wealth (US data)
593
+
594
+
In the previous section we looked at the Gini coefficient for income using US data.
616
595
617
-
As we have discussed the Gini coefficient can also be computed over different distributions such as *income* and *wealth*.
596
+
Now let's look at the Gini coefficient for the distribution of wealth.
618
597
619
-
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.
598
+
We can use the data collected above {ref}`survey of consumer finances <data:survey-consumer-finance>` to look at the Gini coefficient
599
+
computed over the wealth distribution.
620
600
621
-
We can compute the Gini coefficient for net wealth, total income, and labour income over many years.
601
+
The Gini coefficient for net wealthand labour income is computed over many years.
622
602
623
603
```{code-cell} ipython3
624
604
df_income_wealth.year.describe()
625
605
```
626
606
627
-
This code can be used to compute this information over the full dataset.
607
+
**Note:**This code can be used to compute this information over the full dataset.
0 commit comments