Skip to content

Commit cdf794d

Browse files
committed
incorporate some of @jstac comments
1 parent 2707b5d commit cdf794d

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
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.8257332034366344,0.44248654139458693,0.5342948198773417
3-
1953,0.8059487586599325,0.42645440609359514,0.5158978980963705
4-
1956,0.8121790488050629,0.4442694287339931,0.5349293526208135
5-
1959,0.7952068741637919,0.4374934807706156,0.5213985948309419
6-
1962,0.8086945076579375,0.4435843103853644,0.5345127915054356
7-
1965,0.7904149225687939,0.43763715466663433,0.7487860020887759
8-
1968,0.7982885066993506,0.42086207944389026,0.5242396427381537
9-
1971,0.7911574835420256,0.42333442460902515,0.5576454812313486
10-
1977,0.7571418922185218,0.46187678800902543,0.5704448110072071
11-
1983,0.749433540064304,0.43934561846446973,0.5662220844385909
12-
1989,0.7715705301674298,0.51152495816542,0.6013995687471444
13-
1992,0.7508126614055317,0.4740650672076807,0.5983592657979544
14-
1995,0.7569492388110282,0.48965523558400603,0.596977951671693
15-
1998,0.7603291991801175,0.4911744158516888,0.5774462841723299
16-
2001,0.7816118750507037,0.5239092994681126,0.6042739644967319
17-
2004,0.7700355469522371,0.48843503839032426,0.5981432201792735
18-
2007,0.782141377648699,0.5197156312086187,0.6263452195753223
19-
2010,0.8250825295193419,0.5195972120145633,0.6453653328291933
20-
2013,0.8227698931835327,0.5314001749843346,0.6498682917772663
21-
2016,0.8342975903562247,0.5541400068900854,0.670684679337527
2+
1950,0.8257332034366353,0.4424865413945867,0.5342948198773424
3+
1953,0.8059487586599343,0.42645440609359475,0.5158978980963699
4+
1956,0.8121790488050622,0.4442694287339929,0.5349293526208142
5+
1959,0.7952068741637924,0.43749348077061573,0.5213985948309421
6+
1962,0.8086945076579368,0.4435843103853639,0.5345127915054342
7+
1965,0.790414922568795,0.43763715466663367,0.7487860020887751
8+
1968,0.7982885066993514,0.42086207944388976,0.5242396427381543
9+
1971,0.7911574835420238,0.4233344246090258,0.5576454812313485
10+
1977,0.7571418922185226,0.461876788009026,0.5704448110072052
11+
1983,0.7494335400643025,0.4393456184644705,0.5662220844385915
12+
1989,0.7715705301674318,0.511524958165423,0.6013995687471408
13+
1992,0.7508126614055309,0.4740650672076755,0.5983592657979545
14+
1995,0.7569492388110265,0.4896552355840044,0.5969779516716882
15+
1998,0.760329199180118,0.4911744158516898,0.5774462841723345
16+
2001,0.7816118750507034,0.5239092994681134,0.6042739644967283
17+
2004,0.7700355469522369,0.4884350383903255,0.5981432201792665
18+
2007,0.7821413776486987,0.5197156312086179,0.6263452195753251
19+
2010,0.825082529519343,0.5195972120145644,0.6453653328291921
20+
2013,0.8227698931835268,0.5314001749843339,0.6498682917772639
21+
2016,0.8342975903562239,0.5541400068900838,0.6706846793375301

lectures/inequality.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,18 @@ The curve $L$ is just a function $y = L(x)$ that we can plot and interpret.
102102

103103
To create it we first generate data points $(x_i, y_i)$ according to
104104

105+
```{prf:definition}
105106
$$
106107
x_i = \frac{i}{n},
107108
\qquad
108109
y_i = \frac{\sum_{j \leq i} w_j}{\sum_{j \leq n} w_j},
109110
\qquad i = 1, \ldots, n
110111
$$
112+
```
111113

112114
Now the Lorenz curve $L$ is formed from these data points using interpolation.
113115

114-
```{tip}
115116
If we use a line plot in `matplotlib`, the interpolation will be done for us.
116-
```
117117

118118
The meaning of the statement $y = L(x)$ is that the lowest $(100
119119
\times x)$\% of people have $(100 \times y)$\% of all wealth.
@@ -337,11 +337,15 @@ smallest to largest.
337337

338338
The Gini coefficient is defined for the sample above as
339339

340+
```{prf:definition}
341+
:label: define-gini
342+
340343
$$
341344
G :=
342345
\frac{\sum_{i=1}^n \sum_{j = 1}^n |w_j - w_i|}
343346
{2n\sum_{i=1}^n w_i}.
344-
$$ (eq:gini)
347+
$$ ()
348+
```
345349

346350
The Gini coefficient is closely related to the Lorenz curve.
347351

@@ -529,6 +533,7 @@ Let us fetch the data for the USA and request for it to be returned as a `DataFr
529533
```{code-cell} ipython3
530534
data = wb.data.DataFrame("SI.POV.GINI", "USA")
531535
data.head(n=5)
536+
data.columns = data.columns.map(lambda x: int(x.replace('YR',''))) # remove 'YR' in index and convert to int
532537
```
533538

534539
```{tip}
@@ -559,8 +564,9 @@ plt.show()
559564

560565
As can be seen in {numref}`gini_usa1` the Gini coefficient:
561566

562-
1. moves slowly over time, and
563-
2. does not have significant variation in the full range from 0 to 100.
567+
1. trended upward from 1980 to 2020 and then dropped slightly following the COVID pandemic
568+
1. moves slowly over time
569+
3. does not have significant variation in the full range from 0 to 100
564570

565571
Using `pandas` we can take a quick look across all countries and all years in the World Bank dataset.
566572

@@ -569,6 +575,7 @@ By leaving off the `"USA"` this function returns all Gini data that is available
569575
```{code-cell} ipython3
570576
# Fetch gini data for all countries
571577
gini_all = wb.data.DataFrame("SI.POV.GINI")
578+
gini_all.columns = gini_all.columns.map(lambda x: int(x.replace('YR',''))) # remove 'YR' in index and convert to int
572579
573580
# Create a long series with a multi-index of the data to get global min and max values
574581
gini_all = gini_all.unstack(level='economy').dropna()
@@ -588,7 +595,6 @@ Let us zoom in a little on the US data and add some trendlines.
588595
{numref}`gini_usa1` suggests there is a change in trend around the year 1981
589596

590597
```{code-cell} ipython3
591-
data_usa.index = data_usa.index.map(lambda x: int(x.replace('YR',''))) # remove 'YR' in index and convert to int
592598
# Use pandas filters to find data before 1981
593599
pre_1981 = data_usa[data_usa.index <= 1981]
594600
# Use pandas filters to find data after 1981
@@ -808,7 +814,9 @@ Let's take another look at the USA, Norway, and the United Kingdom.
808814

809815
```{code-cell} ipython3
810816
countries = ['USA', 'NOR', 'GBR']
811-
gdppc = wb.data.DataFrame("NY.GDP.PCAP.KD", countries).T
817+
gdppc = wb.data.DataFrame("NY.GDP.PCAP.KD", countries)
818+
gdppc.columns = gdppc.columns.map(lambda x: int(x.replace('YR',''))) # remove 'YR' in index and convert to int
819+
gdppc = gdppc.T
812820
```
813821

814822
We can rearrange the data so that we can plot gdp per capita and the Gini coefficient across years
@@ -829,12 +837,6 @@ plot_data = plot_data.merge(pgdppc, left_index=True, right_index=True)
829837
plot_data.reset_index(inplace=True)
830838
```
831839

832-
We will transform the year column to remove the 'YR' text and return an integer.
833-
834-
```{code-cell} ipython3
835-
plot_data.year = plot_data.year.map(lambda x: int(x.replace('YR','')))
836-
```
837-
838840
Now using plotly to build a plot with gdp per capita on the y-axis and the Gini coefficient on the x-axis.
839841

840842
```{code-cell} ipython3
@@ -853,6 +855,7 @@ plot_data.year = plot_data.year.map(lambda x: x if x in labels else None)
853855
```
854856

855857
(fig:plotly-gini-gdppc-years)=
858+
856859
```{code-cell} ipython3
857860
fig = px.line(plot_data,
858861
x = "gini",

0 commit comments

Comments
 (0)