@@ -414,7 +414,7 @@ varlist = ['n_wealth', # net wealth
414
414
't_income', # total income
415
415
'l_income'] # labor income
416
416
417
- df = df_income_wealth
417
+ df = df_income_wealth
418
418
419
419
# create lists to store Gini for each inequality measure
420
420
@@ -426,7 +426,7 @@ for var in varlist:
426
426
427
427
for year in years:
428
428
# repeat the observations according to their weights
429
- counts = list(round(df[df['year'] == year]['weights'] ))
429
+ counts = list(round(df[df['year'] == year]['weights'] ))
430
430
y = df[df['year'] == year][var].repeat(counts)
431
431
y = np.asarray(y)
432
432
@@ -448,7 +448,7 @@ Let's plot the Gini coefficients for net wealth, labor income and total income.
448
448
``` {code-cell} ipython3
449
449
# use an average to replace an outlier in labor income gini
450
450
ginis_li_new = ginis_li
451
- ginis_li_new[5] = (ginis_li[4] + ginis_li[6]) / 2
451
+ ginis_li_new[5] = (ginis_li[4] + ginis_li[6]) / 2
452
452
```
453
453
454
454
``` {code-cell} ipython3
@@ -493,7 +493,7 @@ ax.plot(years, ginis_ti, marker='o', label="total income")
493
493
ax.set_xlabel(xlabel, fontsize=12)
494
494
ax.set_ylabel(ylabel, fontsize=12)
495
495
496
- ax.legend(fontsize=12)
496
+ ax.legend(fontsize=12)
497
497
plt.show()
498
498
```
499
499
@@ -540,16 +540,16 @@ The following code uses the data from dataframe ``df_income_wealth`` to generate
540
540
# transfer the survey weights from absolute into relative values
541
541
df1 = df_income_wealth
542
542
df2 = df1.groupby('year').sum(numeric_only=True).reset_index()
543
- df3 = df2[['year', 'weights']]
544
- df3.columns = 'year', 'r_weights'
545
- df4 = pd.merge(df3, df1, how="left", on=["year"])
546
- df4['r_weights'] = df4['weights'] / df4['r_weights']
543
+ df3 = df2[['year', 'weights']]
544
+ df3.columns = 'year', 'r_weights'
545
+ df4 = pd.merge(df3, df1, how="left", on=["year"])
546
+ df4['r_weights'] = df4['weights'] / df4['r_weights']
547
547
548
548
# create weighted nw, ti, li
549
549
550
- df4['weighted_n_wealth'] = df4['n_wealth'] * df4['r_weights']
551
- df4['weighted_t_income'] = df4['t_income'] * df4['r_weights']
552
- df4['weighted_l_income'] = df4['l_income'] * df4['r_weights']
550
+ df4['weighted_n_wealth'] = df4['n_wealth'] * df4['r_weights']
551
+ df4['weighted_t_income'] = df4['t_income'] * df4['r_weights']
552
+ df4['weighted_l_income'] = df4['l_income'] * df4['r_weights']
553
553
554
554
# extract two top 10% groups by net wealth and total income.
555
555
@@ -559,7 +559,7 @@ df7 = df4[df4['ti_groups'] == 'Top 10%']
559
559
# calculate the sum of weighted top 10% by net wealth,
560
560
# total income and labor income.
561
561
562
- df5 = df4.groupby('year').sum(numeric_only=True).reset_index()
562
+ df5 = df4.groupby('year').sum(numeric_only=True).reset_index()
563
563
df8 = df6.groupby('year').sum(numeric_only=True).reset_index()
564
564
df9 = df7.groupby('year').sum(numeric_only=True).reset_index()
565
565
@@ -578,7 +578,7 @@ df5['topshare_l_income'] = df5['weighted_l_income_top10'] / \
578
578
579
579
# we only need these vars for top 10 percent shares
580
580
df_topshares = df5[['year', 'topshare_n_wealth',
581
- 'topshare_t_income', 'topshare_l_income']]
581
+ 'topshare_t_income', 'topshare_l_income']]
582
582
```
583
583
584
584
Then let's plot the top shares.
0 commit comments