Skip to content

Commit 23a9913

Browse files
Minor fixes
1 parent 792c47e commit 23a9913

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

lectures/inequality.md

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ The following code block uses data stored in dataframe ``df_income_wealth`` to g
193193
population weights supplied by the SCF.)
194194

195195
```{code-cell} ipython3
196-
:tags: [hide_input]
196+
:tags: [hide-input]
197197
198198
df = df_income_wealth
199199
@@ -408,7 +408,7 @@ The following code creates a list called ``Ginis``.
408408
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.
409409

410410
```{code-cell} ipython3
411-
:tags: [hide_input]
411+
:tags: [hide-input]
412412
413413
varlist = ['n_wealth', # net wealth
414414
't_income', # total income
@@ -535,11 +535,11 @@ The following code uses the data from dataframe ``df_income_wealth`` to generate
535535
``df_topshares`` stores the top 10 percent shares for the total income, the labor income and net wealth from 1950 to 2016 in US.
536536
537537
```{code-cell} ipython3
538-
:tags: [hide_input]
538+
:tags: [hide-input]
539539
540540
# transfer the survey weights from absolute into relative values
541541
df1 = df_income_wealth
542-
df2 = df1.groupby('year').sum(numeric_only=True).reset_index() # group
542+
df2 = df1.groupby('year').sum(numeric_only=True).reset_index()
543543
df3 = df2[['year', 'weights']]
544544
df3.columns = 'year', 'r_weights'
545545
df4 = pd.merge(df3, df1, how="left", on=["year"])
@@ -556,7 +556,8 @@ df4['weighted_l_income'] = df4['l_income'] * df4['r_weights']
556556
df6 = df4[df4['nw_groups'] == 'Top 10%']
557557
df7 = df4[df4['ti_groups'] == 'Top 10%']
558558
559-
# calculate the sum of weighted top 10% by net wealth, total income and labor income.
559+
# calculate the sum of weighted top 10% by net wealth,
560+
# total income and labor income.
560561
561562
df5 = df4.groupby('year').sum(numeric_only=True).reset_index()
562563
df8 = df6.groupby('year').sum(numeric_only=True).reset_index()
@@ -568,12 +569,16 @@ df5['weighted_l_income_top10'] = df9['weighted_l_income']
568569
569570
# calculate the top 10% shares of the three variables.
570571
571-
df5['topshare_n_wealth'] = df5['weighted_n_wealth_top10'] / df5['weighted_n_wealth']
572-
df5['topshare_t_income'] = df5['weighted_t_income_top10'] / df5['weighted_t_income']
573-
df5['topshare_l_income'] = df5['weighted_l_income_top10'] / df5['weighted_l_income']
572+
df5['topshare_n_wealth'] = df5['weighted_n_wealth_top10'] / \
573+
df5['weighted_n_wealth']
574+
df5['topshare_t_income'] = df5['weighted_t_income_top10'] / \
575+
df5['weighted_t_income']
576+
df5['topshare_l_income'] = df5['weighted_l_income_top10'] / \
577+
df5['weighted_l_income']
574578
575579
# we only need these vars for top 10 percent shares
576-
df_topshares = df5[['year', 'topshare_n_wealth', 'topshare_t_income', 'topshare_l_income']]
580+
df_topshares = df5[['year', 'topshare_n_wealth',
581+
'topshare_t_income', 'topshare_l_income']]
577582
```
578583
579584
Then let's plot the top shares.
@@ -592,9 +597,12 @@ ylabel = "top $10\%$ share"
592597
593598
fig, ax = plt.subplots()
594599
595-
ax.plot(years, df_topshares["topshare_l_income"], marker='o', label="labor income")
596-
ax.plot(years, df_topshares["topshare_n_wealth"], marker='o', label="net wealth")
597-
ax.plot(years, df_topshares["topshare_t_income"], marker='o', label="total income")
600+
ax.plot(years, df_topshares["topshare_l_income"],
601+
marker='o', label="labor income")
602+
ax.plot(years, df_topshares["topshare_n_wealth"],
603+
marker='o', label="net wealth")
604+
ax.plot(years, df_topshares["topshare_t_income"],
605+
marker='o', label="total income")
598606
599607
ax.set_xlabel(xlabel, fontsize=12)
600608
ax.set_ylabel(ylabel, fontsize=12)
@@ -762,7 +770,8 @@ ylabel = "top $10\%$ share"
762770
763771
fig, ax = plt.subplots()
764772
765-
ax.plot(years, df_topshares["topshare_n_wealth"], marker='o', label="net wealth-approx")
773+
ax.plot(years, df_topshares["topshare_n_wealth"], marker='o',\
774+
label="net wealth-approx")
766775
ax.plot(years, top_shares_nw, marker='o', label="net wealth-lorenz")
767776
768777
ax.set_xlabel(xlabel, fontsize=12)

0 commit comments

Comments
 (0)