-
-
Couldn't load subscription status.
- Fork 26
[inequality] fix_titles #152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits Select commit Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -4,7 +4,7 @@ jupytext: | |
| extension: .md | ||
| format_name: myst | ||
| format_version: 0.13 | ||
| jupytext_version: 1.14.1 | ||
| jupytext_version: 1.14.5 | ||
| kernelspec: | ||
| display_name: Python 3 (ipykernel) | ||
| language: python | ||
| | @@ -145,7 +145,7 @@ households own just over 40\% of total wealth. | |
| --- | ||
| mystnb: | ||
| figure: | ||
| caption: Lorenz Curves For Simulated Data | ||
| caption: "Lorenz curve of simulated data" | ||
| name: lorenz_simulated | ||
| --- | ||
| n = 2000 | ||
| | @@ -165,8 +165,6 @@ ax.hlines([0.43], [0], [0.8], alpha=0.5, colors='k', ls='--') | |
| ax.set_ylim((0, 1)) | ||
| ax.set_xlim((0, 1)) | ||
| | ||
| plt.title("Lorenz curve of simulated data") # TODO shift to the render | ||
| | ||
| plt.show() | ||
| ``` | ||
| | ||
| | @@ -242,10 +240,10 @@ US in 2016. | |
| --- | ||
| mystnb: | ||
| figure: | ||
| caption: "US Lorenz Curves \n" | ||
| caption: "2016 US Lorenz curves" | ||
| name: lorenz_us | ||
| image: | ||
| alt: lorenz_real | ||
| alt: lorenz_us | ||
| classes: shadow bg-primary | ||
| width: 75% | ||
| --- | ||
| | @@ -256,8 +254,7 @@ ax.plot(f_vals_ti[-1], l_vals_ti[-1], label=f'total income') | |
| ax.plot(f_vals_li[-1], l_vals_li[-1], label=f'labor income') | ||
| ax.plot(f_vals_nw[-1], f_vals_nw[-1], label=f'equality') | ||
| | ||
| ax.legend(fontsize=12) | ||
| plt.title("Lorenz curves of US data in 2016") | ||
| ax.legend(fontsize=12) | ||
| plt.show() | ||
| ``` | ||
| | ||
| | @@ -311,7 +308,7 @@ The idea is that $G=0$ indicates complete equality, while $G=1$ indicates comple | |
| --- | ||
| mystnb: | ||
| figure: | ||
| caption: "Shaded Lorenz curves (simulated data) \n" | ||
| caption: "Shaded lorenz curve of simulated data" | ||
| name: lorenz_gini | ||
| image: | ||
| alt: lorenz_gini | ||
| | @@ -335,8 +332,7 @@ ax.set_ylim((0, 1)) | |
| ax.set_xlim((0, 1)) | ||
| | ||
| ax.text(0.04, 0.5, r'$G = 2 \times$ shaded area', fontsize=12) | ||
| | ||
| plt.title("Shaded lorenz curve of simulated data") | ||
| | ||
| plt.show() | ||
| ``` | ||
| | ||
| | @@ -374,7 +370,7 @@ for σ in σ_vals: | |
| ``` | ||
| | ||
| ```{code-cell} ipython3 | ||
| def plot_inequality_measures(x, y, legend, xlabel, ylabel, title): | ||
| def plot_inequality_measures(x, y, legend, xlabel, ylabel): | ||
| | ||
| fig, ax = plt.subplots() | ||
| ax.plot(x, y, marker='o', label=legend) | ||
| | @@ -383,27 +379,25 @@ def plot_inequality_measures(x, y, legend, xlabel, ylabel, title): | |
| ax.set_ylabel(ylabel, fontsize=12) | ||
| | ||
| ax.legend(fontsize=12) | ||
| plt.title(title) # TODO shift it to the render | ||
| plt.show() | ||
| ``` | ||
| | ||
| ```{code-cell} ipython3 | ||
| --- | ||
| mystnb: | ||
| figure: | ||
| caption: "Lorenz curves (simulated data) \n" | ||
| name: lorenz_simulated_shaded | ||
| caption: "Gini coefficients of simulated data" | ||
| name: gini_simulated | ||
| image: | ||
| alt: gini | ||
| alt: gini_simulated | ||
| classes: shadow bg-primary | ||
| width: 75% | ||
| --- | ||
| plot_inequality_measures(range(k), | ||
| ginis, | ||
| 'simulated', | ||
| '$\sigma$', | ||
| 'gini coefficients', | ||
| 'Gini coefficients of simulated data') | ||
| 'gini coefficients') | ||
| ``` | ||
| | ||
| 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 | |
| --- | ||
| mystnb: | ||
| figure: | ||
| caption: "US Gini Coefficients \n" | ||
| name: gini_us | ||
| caption: "Gini coefficients of US net wealth" | ||
| name: gini_wealth_us | ||
| image: | ||
| alt: gini_us | ||
| alt: gini_wealth_us | ||
| classes: shadow bg-primary | ||
| width: 75% | ||
| --- | ||
| | @@ -483,13 +477,21 @@ ax.plot(years, ginis_nw, marker='o') | |
| | ||
| ax.set_xlabel(xlabel, fontsize=12) | ||
| ax.set_ylabel(ylabel, fontsize=12) | ||
| | ||
| | ||
| plt.title("Gini coefficients of US net wealth data") | ||
| | ||
| plt.show() | ||
| ``` | ||
| | ||
| ```{code-cell} ipython3 | ||
| --- | ||
| mystnb: | ||
| figure: | ||
| caption: "Gini coefficients of US income" | ||
| name: gini_income_us | ||
| image: | ||
| alt: gini_income_us | ||
| classes: shadow bg-primary | ||
| width: 75% | ||
| --- | ||
| xlabel = "year" | ||
| ylabel = "gini coefficient" | ||
| | ||
| | @@ -501,12 +503,11 @@ ax.plot(years, ginis_ti, marker='o', label="total income") | |
| ax.set_xlabel(xlabel, fontsize=12) | ||
| ax.set_ylabel(ylabel, fontsize=12) | ||
| | ||
| ax.legend(fontsize=12) | ||
| plt.title("Gini coefficients of US income data") | ||
| ax.legend(fontsize=12) | ||
| plt.show() | ||
| ``` | ||
| | ||
| **TEST ===>** Here is a {ref}`gini_us` and a {numref}`gini_us` | ||
| **TEST ===>** Here is a {ref}`gini_income_us` and a {numref}`gini_income_us` | ||
| ||
| | ||
| We see that, by this measure, inequality in wealth and income has risen | ||
| substantially since 1980. | ||
| | @@ -550,7 +551,7 @@ The following code uses the data from dataframe ``df_income_wealth`` to generate | |
| | ||
| # transfer the survey weights from absolute into relative values | ||
| df1 = df_income_wealth | ||
| df2 = df1.groupby('year').sum().reset_index() # group | ||
| df2 = df1.groupby('year').sum(numeric_only=True).reset_index() # group | ||
| df3 = df2[['year', 'weights']] | ||
| df3.columns = 'year', 'r_weights' | ||
| df4 = pd.merge(df3, df1, how="left", on=["year"]) | ||
| | @@ -569,9 +570,9 @@ df7 = df4[df4['ti_groups'] == 'Top 10%'] | |
| | ||
| # calculate the sum of weighted top 10% by net wealth, total income and labor income. | ||
| | ||
| df5 = df4.groupby('year').sum().reset_index() | ||
| df8 = df6.groupby('year').sum().reset_index() | ||
| df9 = df7.groupby('year').sum().reset_index() | ||
| df5 = df4.groupby('year').sum(numeric_only=True).reset_index() | ||
| df8 = df6.groupby('year').sum(numeric_only=True).reset_index() | ||
| df9 = df7.groupby('year').sum(numeric_only=True).reset_index() | ||
| | ||
| df5['weighted_n_wealth_top10'] = df8['weighted_n_wealth'] | ||
| df5['weighted_t_income_top10'] = df9['weighted_t_income'] | ||
| | @@ -590,6 +591,16 @@ df_topshares = df5[['year', 'topshare_n_wealth', 'topshare_t_income', 'topshare_ | |
| Then let's plot the top shares. | ||
| | ||
| ```{code-cell} ipython3 | ||
| --- | ||
| mystnb: | ||
| figure: | ||
| caption: "US top shares" | ||
| name: top_shares_us | ||
| image: | ||
| alt: top_shares_us | ||
| classes: shadow bg-primary | ||
| width: 75% | ||
| --- | ||
| xlabel = "year" | ||
| ylabel = "top $10\%$ share" | ||
| | ||
| | @@ -603,7 +614,6 @@ ax.set_xlabel(xlabel, fontsize=12) | |
| ax.set_ylabel(ylabel, fontsize=12) | ||
| | ||
| ax.legend(fontsize=12) | ||
| plt.title("Top shares of US data") # TODO shift to the render | ||
| plt.show() | ||
| ``` | ||
| | ||
| | @@ -662,12 +672,21 @@ for σ in σ_vals: | |
| ``` | ||
| | ||
| ```{code-cell} ipython3 | ||
| --- | ||
| mystnb: | ||
| figure: | ||
| caption: "Top shares of simulated data" | ||
| name: top_shares_simulated | ||
| image: | ||
| alt: top_shares_simulated | ||
| classes: shadow bg-primary | ||
| width: 75% | ||
| --- | ||
| plot_inequality_measures(range(len(topshares)), | ||
| topshares, | ||
| "simulated data", | ||
| "year", | ||
| "top $10\%$ share", | ||
| "Top $10\%$ share of simulated data") | ||
| "top $10\%$ share") | ||
| ``` | ||
| | ||
| ```{solution-end} | ||
| | @@ -708,6 +727,16 @@ for f_val, l_val in zip(f_vals_nw, l_vals_nw): | |
| ``` | ||
| | ||
| ```{code-cell} ipython3 | ||
| --- | ||
| mystnb: | ||
| figure: | ||
| caption: "US top shares: approximation vs Lorenz" | ||
| name: top_shares_us_al | ||
| image: | ||
| alt: top_shares_us_al | ||
| classes: shadow bg-primary | ||
| width: 75% | ||
| --- | ||
| xlabel = "year" | ||
| ylabel = "top $10\%$ share" | ||
| | ||
| | @@ -720,7 +749,6 @@ ax.set_xlabel(xlabel, fontsize=12) | |
| ax.set_ylabel(ylabel, fontsize=12) | ||
| | ||
| ax.legend(fontsize=12) | ||
| plt.title("Top $10\%$ share of net wealth: approximation vs lorenz") | ||
| plt.show() | ||
| ``` | ||
| | ||
| | ||
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lorenz -> Lorenz