Skip to content
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

[inequality] Update exercise 3 #498

Merged
merged 13 commits into from
Jul 5, 2024
6 changes: 3 additions & 3 deletions lectures/inequality.md
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ df_income_wealth.head(n=4)
We will focus on wealth variable `n_wealth` to compute a Gini coefficient for the year 1990.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@longye-tian can we either change 1990 in the text to 2016 or the otherway around based on the correct context?


```{code-cell} ipython3
data = df_income_wealth[df_income_wealth.year == 2016]
data = df_income_wealth[df_income_wealth.year == 2016].sample(3000, random_state=1)
```

```{code-cell} ipython3
Expand All @@ -1094,7 +1094,7 @@ data.head(n=2)
We can first compute the Gini coefficient using the function defined in the lecture above.

```{code-cell} ipython3
gini_coefficient(data.n_wealth.values[1:3000])
gini_coefficient(data.n_wealth.values)
```

Now we can write a vectorized version using `numpy`
Expand All @@ -1108,7 +1108,7 @@ def gini(y):
return g_sum / (2 * n * np.sum(y))
```
```{code-cell} ipython3
gini(data.n_wealth.values[1:3000])
gini(data.n_wealth.values)
```
Let's simulate five populations by drawing from a lognormal distribution as before

Expand Down