Skip to content

Commit 42031d9

Browse files
authored
Merge pull request #152 from QuantEcon/inequality_update
[inequality] fix_titles
2 parents 2d87cab + cadb543 commit 42031d9

File tree

1 file changed

+62
-36
lines changed

1 file changed

+62
-36
lines changed

lectures/inequality.md

Lines changed: 62 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jupytext:
44
extension: .md
55
format_name: myst
66
format_version: 0.13
7-
jupytext_version: 1.14.1
7+
jupytext_version: 1.14.5
88
kernelspec:
99
display_name: Python 3 (ipykernel)
1010
language: python
@@ -145,7 +145,7 @@ households own just over 40\% of total wealth.
145145
---
146146
mystnb:
147147
figure:
148-
caption: Lorenz Curves For Simulated Data
148+
caption: "Lorenz curve of simulated data"
149149
name: lorenz_simulated
150150
---
151151
n = 2000
@@ -165,8 +165,6 @@ ax.hlines([0.43], [0], [0.8], alpha=0.5, colors='k', ls='--')
165165
ax.set_ylim((0, 1))
166166
ax.set_xlim((0, 1))
167167
168-
plt.title("Lorenz curve of simulated data") # TODO shift to the render
169-
170168
plt.show()
171169
```
172170

@@ -242,10 +240,10 @@ US in 2016.
242240
---
243241
mystnb:
244242
figure:
245-
caption: "US Lorenz Curves \n"
243+
caption: "2016 US Lorenz curves"
246244
name: lorenz_us
247245
image:
248-
alt: lorenz_real
246+
alt: lorenz_us
249247
classes: shadow bg-primary
250248
width: 75%
251249
---
@@ -256,8 +254,7 @@ ax.plot(f_vals_ti[-1], l_vals_ti[-1], label=f'total income')
256254
ax.plot(f_vals_li[-1], l_vals_li[-1], label=f'labor income')
257255
ax.plot(f_vals_nw[-1], f_vals_nw[-1], label=f'equality')
258256
259-
ax.legend(fontsize=12)
260-
plt.title("Lorenz curves of US data in 2016")
257+
ax.legend(fontsize=12)
261258
plt.show()
262259
```
263260

@@ -311,7 +308,7 @@ The idea is that $G=0$ indicates complete equality, while $G=1$ indicates comple
311308
---
312309
mystnb:
313310
figure:
314-
caption: "Shaded Lorenz curves (simulated data) \n"
311+
caption: "Shaded Lorenz curve of simulated data"
315312
name: lorenz_gini
316313
image:
317314
alt: lorenz_gini
@@ -335,8 +332,7 @@ ax.set_ylim((0, 1))
335332
ax.set_xlim((0, 1))
336333
337334
ax.text(0.04, 0.5, r'$G = 2 \times$ shaded area', fontsize=12)
338-
339-
plt.title("Shaded lorenz curve of simulated data")
335+
340336
plt.show()
341337
```
342338

@@ -374,7 +370,7 @@ for σ in σ_vals:
374370
```
375371

376372
```{code-cell} ipython3
377-
def plot_inequality_measures(x, y, legend, xlabel, ylabel, title):
373+
def plot_inequality_measures(x, y, legend, xlabel, ylabel):
378374
379375
fig, ax = plt.subplots()
380376
ax.plot(x, y, marker='o', label=legend)
@@ -383,27 +379,25 @@ def plot_inequality_measures(x, y, legend, xlabel, ylabel, title):
383379
ax.set_ylabel(ylabel, fontsize=12)
384380
385381
ax.legend(fontsize=12)
386-
plt.title(title) # TODO shift it to the render
387382
plt.show()
388383
```
389384

390385
```{code-cell} ipython3
391386
---
392387
mystnb:
393388
figure:
394-
caption: "Lorenz curves (simulated data) \n"
395-
name: lorenz_simulated_shaded
389+
caption: "Gini coefficients of simulated data"
390+
name: gini_simulated
396391
image:
397-
alt: gini
392+
alt: gini_simulated
398393
classes: shadow bg-primary
399394
width: 75%
400395
---
401396
plot_inequality_measures(range(k),
402397
ginis,
403398
'simulated',
404399
'$\sigma$',
405-
'gini coefficients',
406-
'Gini coefficients of simulated data')
400+
'gini coefficients')
407401
```
408402

409403
The plots show that inequality rises with $\sigma$, according to the Gini
@@ -467,10 +461,10 @@ ginis_li_new[5] = (ginis_li[4] + ginis_li[6]) / 2
467461
---
468462
mystnb:
469463
figure:
470-
caption: "US Gini Coefficients \n"
471-
name: gini_us
464+
caption: "Gini coefficients of US net wealth"
465+
name: gini_wealth_us
472466
image:
473-
alt: gini_us
467+
alt: gini_wealth_us
474468
classes: shadow bg-primary
475469
width: 75%
476470
---
@@ -483,13 +477,21 @@ ax.plot(years, ginis_nw, marker='o')
483477
484478
ax.set_xlabel(xlabel, fontsize=12)
485479
ax.set_ylabel(ylabel, fontsize=12)
486-
487-
488-
plt.title("Gini coefficients of US net wealth data")
480+
489481
plt.show()
490482
```
491483

492484
```{code-cell} ipython3
485+
---
486+
mystnb:
487+
figure:
488+
caption: "Gini coefficients of US income"
489+
name: gini_income_us
490+
image:
491+
alt: gini_income_us
492+
classes: shadow bg-primary
493+
width: 75%
494+
---
493495
xlabel = "year"
494496
ylabel = "gini coefficient"
495497
@@ -501,13 +503,10 @@ ax.plot(years, ginis_ti, marker='o', label="total income")
501503
ax.set_xlabel(xlabel, fontsize=12)
502504
ax.set_ylabel(ylabel, fontsize=12)
503505
504-
ax.legend(fontsize=12)
505-
plt.title("Gini coefficients of US income data")
506+
ax.legend(fontsize=12)
506507
plt.show()
507508
```
508509

509-
**TEST ===>** Here is a {ref}`gini_us` and a {numref}`gini_us`
510-
511510
We see that, by this measure, inequality in wealth and income has risen
512511
substantially since 1980.
513512

@@ -550,7 +549,7 @@ The following code uses the data from dataframe ``df_income_wealth`` to generate
550549
551550
# transfer the survey weights from absolute into relative values
552551
df1 = df_income_wealth
553-
df2 = df1.groupby('year').sum().reset_index() # group
552+
df2 = df1.groupby('year').sum(numeric_only=True).reset_index() # group
554553
df3 = df2[['year', 'weights']]
555554
df3.columns = 'year', 'r_weights'
556555
df4 = pd.merge(df3, df1, how="left", on=["year"])
@@ -569,9 +568,9 @@ df7 = df4[df4['ti_groups'] == 'Top 10%']
569568
570569
# calculate the sum of weighted top 10% by net wealth, total income and labor income.
571570
572-
df5 = df4.groupby('year').sum().reset_index()
573-
df8 = df6.groupby('year').sum().reset_index()
574-
df9 = df7.groupby('year').sum().reset_index()
571+
df5 = df4.groupby('year').sum(numeric_only=True).reset_index()
572+
df8 = df6.groupby('year').sum(numeric_only=True).reset_index()
573+
df9 = df7.groupby('year').sum(numeric_only=True).reset_index()
575574
576575
df5['weighted_n_wealth_top10'] = df8['weighted_n_wealth']
577576
df5['weighted_t_income_top10'] = df9['weighted_t_income']
@@ -590,6 +589,16 @@ df_topshares = df5[['year', 'topshare_n_wealth', 'topshare_t_income', 'topshare_
590589
Then let's plot the top shares.
591590
592591
```{code-cell} ipython3
592+
---
593+
mystnb:
594+
figure:
595+
caption: "US top shares"
596+
name: top_shares_us
597+
image:
598+
alt: top_shares_us
599+
classes: shadow bg-primary
600+
width: 75%
601+
---
593602
xlabel = "year"
594603
ylabel = "top $10\%$ share"
595604
@@ -603,7 +612,6 @@ ax.set_xlabel(xlabel, fontsize=12)
603612
ax.set_ylabel(ylabel, fontsize=12)
604613
605614
ax.legend(fontsize=12)
606-
plt.title("Top shares of US data") # TODO shift to the render
607615
plt.show()
608616
```
609617
@@ -662,12 +670,21 @@ for σ in σ_vals:
662670
```
663671
664672
```{code-cell} ipython3
673+
---
674+
mystnb:
675+
figure:
676+
caption: "Top shares of simulated data"
677+
name: top_shares_simulated
678+
image:
679+
alt: top_shares_simulated
680+
classes: shadow bg-primary
681+
width: 75%
682+
---
665683
plot_inequality_measures(range(len(topshares)),
666684
topshares,
667685
"simulated data",
668686
"year",
669-
"top $10\%$ share",
670-
"Top $10\%$ share of simulated data")
687+
"top $10\%$ share")
671688
```
672689
673690
```{solution-end}
@@ -708,6 +725,16 @@ for f_val, l_val in zip(f_vals_nw, l_vals_nw):
708725
```
709726
710727
```{code-cell} ipython3
728+
---
729+
mystnb:
730+
figure:
731+
caption: "US top shares: approximation vs Lorenz"
732+
name: top_shares_us_al
733+
image:
734+
alt: top_shares_us_al
735+
classes: shadow bg-primary
736+
width: 75%
737+
---
711738
xlabel = "year"
712739
ylabel = "top $10\%$ share"
713740
@@ -720,7 +747,6 @@ ax.set_xlabel(xlabel, fontsize=12)
720747
ax.set_ylabel(ylabel, fontsize=12)
721748
722749
ax.legend(fontsize=12)
723-
plt.title("Top $10\%$ share of net wealth: approximation vs lorenz")
724750
plt.show()
725751
```
726752

0 commit comments

Comments
 (0)