@@ -4,7 +4,7 @@ jupytext:
4
4
extension : .md
5
5
format_name : myst
6
6
format_version : 0.13
7
- jupytext_version : 1.14.1
7
+ jupytext_version : 1.14.5
8
8
kernelspec :
9
9
display_name : Python 3 (ipykernel)
10
10
language : python
@@ -145,7 +145,7 @@ households own just over 40\% of total wealth.
145
145
---
146
146
mystnb:
147
147
figure:
148
- caption: Lorenz Curves For Simulated Data
148
+ caption: " Lorenz curve of simulated data"
149
149
name: lorenz_simulated
150
150
---
151
151
n = 2000
@@ -165,8 +165,6 @@ ax.hlines([0.43], [0], [0.8], alpha=0.5, colors='k', ls='--')
165
165
ax.set_ylim((0, 1))
166
166
ax.set_xlim((0, 1))
167
167
168
- plt.title("Lorenz curve of simulated data") # TODO shift to the render
169
-
170
168
plt.show()
171
169
```
172
170
@@ -242,10 +240,10 @@ US in 2016.
242
240
---
243
241
mystnb:
244
242
figure:
245
- caption: "US Lorenz Curves \n "
243
+ caption: "2016 US Lorenz curves "
246
244
name: lorenz_us
247
245
image:
248
- alt: lorenz_real
246
+ alt: lorenz_us
249
247
classes: shadow bg-primary
250
248
width: 75%
251
249
---
@@ -256,8 +254,7 @@ ax.plot(f_vals_ti[-1], l_vals_ti[-1], label=f'total income')
256
254
ax.plot(f_vals_li[-1], l_vals_li[-1], label=f'labor income')
257
255
ax.plot(f_vals_nw[-1], f_vals_nw[-1], label=f'equality')
258
256
259
- ax.legend(fontsize=12)
260
- plt.title("Lorenz curves of US data in 2016")
257
+ ax.legend(fontsize=12)
261
258
plt.show()
262
259
```
263
260
@@ -311,7 +308,7 @@ The idea is that $G=0$ indicates complete equality, while $G=1$ indicates comple
311
308
---
312
309
mystnb:
313
310
figure:
314
- caption: "Shaded Lorenz curves ( simulated data) \n "
311
+ caption: "Shaded Lorenz curve of simulated data"
315
312
name: lorenz_gini
316
313
image:
317
314
alt: lorenz_gini
@@ -335,8 +332,7 @@ ax.set_ylim((0, 1))
335
332
ax.set_xlim((0, 1))
336
333
337
334
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
+
340
336
plt.show()
341
337
```
342
338
@@ -374,7 +370,7 @@ for σ in σ_vals:
374
370
```
375
371
376
372
``` {code-cell} ipython3
377
- def plot_inequality_measures(x, y, legend, xlabel, ylabel, title ):
373
+ def plot_inequality_measures(x, y, legend, xlabel, ylabel):
378
374
379
375
fig, ax = plt.subplots()
380
376
ax.plot(x, y, marker='o', label=legend)
@@ -383,27 +379,25 @@ def plot_inequality_measures(x, y, legend, xlabel, ylabel, title):
383
379
ax.set_ylabel(ylabel, fontsize=12)
384
380
385
381
ax.legend(fontsize=12)
386
- plt.title(title) # TODO shift it to the render
387
382
plt.show()
388
383
```
389
384
390
385
``` {code-cell} ipython3
391
386
---
392
387
mystnb:
393
388
figure:
394
- caption: "Lorenz curves ( simulated data) \n "
395
- name: lorenz_simulated_shaded
389
+ caption: "Gini coefficients of simulated data"
390
+ name: gini_simulated
396
391
image:
397
- alt: gini
392
+ alt: gini_simulated
398
393
classes: shadow bg-primary
399
394
width: 75%
400
395
---
401
396
plot_inequality_measures(range(k),
402
397
ginis,
403
398
'simulated',
404
399
'$\sigma$',
405
- 'gini coefficients',
406
- 'Gini coefficients of simulated data')
400
+ 'gini coefficients')
407
401
```
408
402
409
403
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
467
461
---
468
462
mystnb:
469
463
figure:
470
- caption: "US Gini Coefficients \n "
471
- name: gini_us
464
+ caption: "Gini coefficients of US net wealth "
465
+ name: gini_wealth_us
472
466
image:
473
- alt: gini_us
467
+ alt: gini_wealth_us
474
468
classes: shadow bg-primary
475
469
width: 75%
476
470
---
@@ -483,13 +477,21 @@ ax.plot(years, ginis_nw, marker='o')
483
477
484
478
ax.set_xlabel(xlabel, fontsize=12)
485
479
ax.set_ylabel(ylabel, fontsize=12)
486
-
487
-
488
- plt.title("Gini coefficients of US net wealth data")
480
+
489
481
plt.show()
490
482
```
491
483
492
484
``` {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
+ ---
493
495
xlabel = "year"
494
496
ylabel = "gini coefficient"
495
497
@@ -501,13 +503,10 @@ ax.plot(years, ginis_ti, marker='o', label="total income")
501
503
ax.set_xlabel(xlabel, fontsize=12)
502
504
ax.set_ylabel(ylabel, fontsize=12)
503
505
504
- ax.legend(fontsize=12)
505
- plt.title("Gini coefficients of US income data")
506
+ ax.legend(fontsize=12)
506
507
plt.show()
507
508
```
508
509
509
- ** TEST ===>** Here is a {ref}` gini_us ` and a {numref}` gini_us `
510
-
511
510
We see that, by this measure, inequality in wealth and income has risen
512
511
substantially since 1980.
513
512
@@ -550,7 +549,7 @@ The following code uses the data from dataframe ``df_income_wealth`` to generate
550
549
551
550
# transfer the survey weights from absolute into relative values
552
551
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
554
553
df3 = df2[['year', 'weights']]
555
554
df3.columns = 'year', 'r_weights'
556
555
df4 = pd.merge(df3, df1, how="left", on=["year"])
@@ -569,9 +568,9 @@ df7 = df4[df4['ti_groups'] == 'Top 10%']
569
568
570
569
# calculate the sum of weighted top 10% by net wealth, total income and labor income.
571
570
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()
575
574
576
575
df5['weighted_n_wealth_top10'] = df8['weighted_n_wealth']
577
576
df5['weighted_t_income_top10'] = df9['weighted_t_income']
@@ -590,6 +589,16 @@ df_topshares = df5[['year', 'topshare_n_wealth', 'topshare_t_income', 'topshare_
590
589
Then let's plot the top shares.
591
590
592
591
```{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
+ ---
593
602
xlabel = "year"
594
603
ylabel = "top $10\%$ share"
595
604
@@ -603,7 +612,6 @@ ax.set_xlabel(xlabel, fontsize=12)
603
612
ax.set_ylabel(ylabel, fontsize=12)
604
613
605
614
ax.legend(fontsize=12)
606
- plt.title("Top shares of US data") # TODO shift to the render
607
615
plt.show()
608
616
```
609
617
@@ -662,12 +670,21 @@ for σ in σ_vals:
662
670
```
663
671
664
672
```{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
+ ---
665
683
plot_inequality_measures(range(len(topshares)),
666
684
topshares,
667
685
"simulated data",
668
686
"year",
669
- "top $10\%$ share",
670
- "Top $10\%$ share of simulated data")
687
+ "top $10\%$ share")
671
688
```
672
689
673
690
```{solution-end}
@@ -708,6 +725,16 @@ for f_val, l_val in zip(f_vals_nw, l_vals_nw):
708
725
```
709
726
710
727
```{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
+ ---
711
738
xlabel = "year"
712
739
ylabel = "top $10\%$ share"
713
740
@@ -720,7 +747,6 @@ ax.set_xlabel(xlabel, fontsize=12)
720
747
ax.set_ylabel(ylabel, fontsize=12)
721
748
722
749
ax.legend(fontsize=12)
723
- plt.title("Top $10\%$ share of net wealth: approximation vs lorenz")
724
750
plt.show()
725
751
```
726
752
0 commit comments