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
@@ -61,11 +61,7 @@ In this lecture we discuss standard measures of inequality used in economic rese
61
61
62
62
For each of these measures, we will look at both simulated and real data.
63
63
64
-
We need to install the `quantecon` package.
65
-
66
-
```{code-cell} ipython3
67
-
!pip install quantecon
68
-
```
64
+
+++
69
65
70
66
We will also use the following imports.
71
67
@@ -74,7 +70,7 @@ import pandas as pd
74
70
import numpy as np
75
71
import matplotlib.pyplot as plt
76
72
import random as rd
77
-
import quantecon as qe
73
+
import wbgapi as wb
78
74
```
79
75
80
76
## The Lorenz curve
@@ -92,7 +88,7 @@ We suppose that the sample $w_1, \ldots, w_n$ has been sorted from smallest to l
92
88
93
89
To aid our interpretation, suppose that we are measuring wealth
94
90
95
-
* $w_1$ is the wealth of the poorest member of the population and
91
+
* $w_1$ is the wealth of the poorest member of the population, and
96
92
* $w_n$ is the wealth of the richest member of the population.
97
93
98
94
The curve $L$ is just a function $y = L(x)$ that we can plot and interpret.
@@ -187,7 +183,7 @@ distribution and treat these draws as our population.
187
183
188
184
The straight 45-degree line ($x=L(x)$ for all $x$) corresponds to perfect equality.
189
185
190
-
The lognormal draws produce a less equal distribution.
186
+
The log-normal draws produce a less equal distribution.
191
187
192
188
For example, if we imagine these draws as being observations of wealth across
193
189
a sample of households, then the dashed lines show that the bottom 80\% of
@@ -223,6 +219,8 @@ plt.show()
223
219
224
220
Next let's look at the real data, focusing on income and wealth in the US in 2016.
225
221
222
+
(data:survey-consumer-finance)=
223
+
226
224
The following code block imports a subset of the dataset `SCF_plus`,
227
225
which is derived from the [Survey of Consumer Finances](https://en.wikipedia.org/wiki/Survey_of_Consumer_Finances) (SCF).
228
226
@@ -333,9 +331,8 @@ The Gini coefficient is defined for the sample above as
333
331
334
332
$$
335
333
G :=
336
-
\frac
337
-
{\sum_{i=1}^n \sum_{j = 1}^n |w_j - w_i|}
338
-
{2n\sum_{i=1}^n w_i}.
334
+
\frac{\sum_{i=1}^n \sum_{j = 1}^n |w_j - w_i|}
335
+
{2n\sum_{i=1}^n w_i}.
339
336
$$ (eq:gini)
340
337
341
338
@@ -439,7 +436,7 @@ ginis = []
439
436
for σ in σ_vals:
440
437
μ = -σ**2 / 2
441
438
y = np.exp(μ + σ * np.random.randn(n))
442
-
ginis.append(qe.gini_coefficient(y))
439
+
ginis.append(gini_coefficient(y))
443
440
```
444
441
445
442
```{code-cell} ipython3
@@ -474,14 +471,131 @@ coefficient.
474
471
475
472
### Gini coefficient dynamics for US data
476
473
477
-
Now let's look at Gini coefficients for US data derived from the SCF.
474
+
Now let's look at Gini coefficients for US data.
478
475
479
-
The following code creates a list called `ginis`.
476
+
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).
480
477
481
-
It stores data of Gini coefficients generated from the dataframe `df_income_wealth` and method [gini_coefficient](https://quanteconpy.readthedocs.io/en/latest/tools/inequality.html#quantecon.inequality.gini_coefficient), from [QuantEcon](https://quantecon.org/quantecon-py/) library.
478
+
Let's search the world bank data for gini to find the Series ID.
482
479
483
480
```{code-cell} ipython3
484
-
:tags: [hide-input]
481
+
wb.search("gini")
482
+
```
483
+
484
+
We now know the series ID is `SI.POV.GINI`.
485
+
486
+
```{tip}
487
+
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.
488
+
```
489
+
490
+
Let us fetch the data for the USA.
491
+
492
+
```{code-cell} ipython3
493
+
data = wb.data.DataFrame("SI.POV.GINI", "USA")
494
+
```
495
+
496
+
```{code-cell} ipython3
497
+
data
498
+
```
499
+
500
+
```{note}
501
+
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
502
+
```
503
+
504
+
```{code-cell} ipython3
505
+
data = data.T
506
+
data_usa = data['USA']
507
+
```
508
+
509
+
```{code-cell} ipython3
510
+
fig, ax = plt.subplots()
511
+
ax = data_usa.plot(ax=ax)
512
+
ax.set_ylim(0,data_usa.max()+5)
513
+
plt.show()
514
+
```
515
+
516
+
The gini coefficient does not have significant variation in the full range from 0 to 100.
517
+
518
+
In fact we can take a quick look across all countries and all years in the world bank dataset to observe this.
519
+
520
+
```{code-cell} ipython3
521
+
gini_all = wb.data.DataFrame("SI.POV.GINI")
522
+
```
523
+
524
+
```{code-cell} ipython3
525
+
# Create a long series with a multi-index of the data to get global min and max values
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).
579
+
580
+
```{admonition} TODO
581
+
:class: warning
582
+
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
583
+
```
584
+
585
+
+++
586
+
587
+
## Comparing income and wealth inequality (the US case)
588
+
589
+
+++
590
+
591
+
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.
592
+
593
+
Let's compute the gin coefficient for net wealth, total income, and labour income.
594
+
595
+
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.
0 commit comments