Skip to content

Commit e5d34b4

Browse files
committed
Incorporate @jstac feedback and comments
1 parent 0ee53aa commit e5d34b4

File tree

1 file changed

+38
-76
lines changed

1 file changed

+38
-76
lines changed

lectures/inequality.md

Lines changed: 38 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ $$
410410
It is an average measure of deviation from the line of equality.
411411

412412
```{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)
414414
```
415415

416416
### Gini coefficient of simulated data
@@ -507,9 +507,9 @@ plt.show()
507507
The plots show that inequality rises with $\sigma$, according to the Gini
508508
coefficient.
509509

510-
### Gini coefficient for US data (income)
510+
### Gini coefficient for income (US data)
511511

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.
513513

514514
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).
515515

@@ -523,49 +523,8 @@ We now know the series ID is `SI.POV.GINI`.
523523

524524
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.
525525

526-
Let us fetch the data for the USA and request for it to be returned as a `DataFrame`.
527-
528-
```{code-cell} ipython3
529-
data = wb.data.DataFrame("SI.POV.GINI", "USA")
530-
data.head(n=5)
531-
# remove 'YR' in index and convert to integer
532-
data.columns = data.columns.map(lambda x: int(x.replace('YR','')))
533-
```
534-
535-
**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-
565526
Using `pandas` we can take a quick look across all countries and all years in the World Bank dataset.
566527

567-
By leaving off the `"USA"` this function returns all Gini data that is available.
568-
569528
```{code-cell} ipython3
570529
---
571530
mystnb:
@@ -588,43 +547,64 @@ ax.set_ylabel("frequency")
588547
plt.show()
589548
```
590549

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.
592552

593-
{numref}`gini_usa1` suggests there is a change in trend around the year 1980.
553+
Let us fetch the data `DataFrame` for the USA.
554+
555+
```{code-cell} ipython3
556+
data = wb.data.DataFrame("SI.POV.GINI", "USA")
557+
data.head(n=5)
558+
# remove 'YR' in index and convert to integer
559+
data.columns = data.columns.map(lambda x: int(x.replace('YR','')))
560+
```
561+
562+
**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+
```
594568

595569
Let us zoom on the US data so we can more clearly observe trends.
596570

597571
```{code-cell} ipython3
598572
---
599573
mystnb:
600574
figure:
601-
caption: Gini coefficients (USA)
602-
name: gini_usa_trend
575+
caption: Gini coefficients for income distribution (USA)
576+
name: gini_usa1
603577
---
604578
fig, ax = plt.subplots()
605579
ax = data_usa.plot(ax=ax)
606580
ax.set_ylim(data_usa.min()-1, data_usa.max()+1)
607-
ax.set_ylabel("Gini coefficient")
581+
ax.set_ylabel("Gini coefficient (income)")
608582
ax.set_xlabel("year")
609583
plt.show()
610584
```
611585

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
613590

614591
(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.
616595

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.
618597

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.
620600

621-
We can compute the Gini coefficient for net wealth, total income, and labour income over many years.
601+
The Gini coefficient for net wealth and labour income is computed over many years.
622602

623603
```{code-cell} ipython3
624604
df_income_wealth.year.describe()
625605
```
626606

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.
628608

629609
```{code-cell} ipython3
630610
:tags: [skip-execution, hide-input, hide-output]
@@ -672,7 +652,7 @@ ginis = pd.read_csv("_static/lecture_specific/inequality/usa-gini-nwealth-tincom
672652
ginis.head(n=5)
673653
```
674654

675-
Let's plot the Gini coefficients for net wealth, labor income and total income.
655+
Let's plot the Gini coefficients for net wealth.
676656

677657
```{code-cell} ipython3
678658
---
@@ -696,24 +676,6 @@ We will smooth our data and take an average of the data either side of it for th
696676
ginis["l_income"][1965] = (ginis["l_income"][1962] + ginis["l_income"][1968]) / 2
697677
```
698678

699-
Now looking at US income for both labour and a total income.
700-
701-
```{code-cell} ipython3
702-
---
703-
mystnb:
704-
figure:
705-
caption: Gini coefficients of US income
706-
name: gini_income_us
707-
---
708-
fig, ax = plt.subplots()
709-
ax.plot(years, ginis["l_income"], marker='o', label="labor income")
710-
ax.plot(years, ginis["t_income"], marker='o', label="total income")
711-
ax.set_xlabel("year")
712-
ax.set_ylabel("Gini coefficient")
713-
ax.legend()
714-
plt.show()
715-
```
716-
717679
Now we can compare net wealth and labour income.
718680

719681
```{code-cell} ipython3
@@ -756,7 +718,7 @@ Let us compare three western economies: USA, United Kingdom, and Norway
756718
---
757719
mystnb:
758720
figure:
759-
caption: Gini coefficients (USA, United Kingdom, and Norway)
721+
caption: Gini coefficients for income (USA, United Kingdom, and Norway)
760722
name: gini_usa_gbr_nor1
761723
---
762724
ax = data[['USA','GBR', 'NOR']].plot()
@@ -780,7 +742,7 @@ We can use the `.ffill()` method to copy and bring forward the last known value
780742
---
781743
mystnb:
782744
figure:
783-
caption: Gini coefficients (USA, United Kingdom, and Norway)
745+
caption: Gini coefficients for income (USA, United Kingdom, and Norway)
784746
name: gini_usa_gbr_nor2
785747
---
786748
data['NOR'] = data['NOR'].ffill()

0 commit comments

Comments
 (0)