Skip to content

Commit 163c65c

Browse files
Copilotmmcky
andcommitted
Fix critical style guide violations in wealth_dynamics.md
Co-authored-by: mmcky <8263752+mmcky@users.noreply.github.com>
1 parent f82a1dc commit 163c65c

File tree

1 file changed

+56
-86
lines changed

1 file changed

+56
-86
lines changed

lectures/wealth_dynamics.md

Lines changed: 56 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,13 @@ tags: [hide-output]
3838

3939
## Overview
4040

41-
This notebook gives an introduction to wealth distribution dynamics, with a
42-
focus on
41+
This notebook gives an introduction to wealth distribution dynamics, with a focus on
4342

4443
* modeling and computing the wealth distribution via simulation,
4544
* measures of inequality such as the Lorenz curve and Gini coefficient, and
4645
* how inequality is affected by the properties of wage income and returns on assets.
4746

48-
One interesting property of the wealth distribution we discuss is Pareto
49-
tails.
47+
One interesting property of the wealth distribution we discuss is **Pareto tails**.
5048

5149
The wealth distribution in many countries exhibits a Pareto tail
5250

@@ -59,14 +57,13 @@ It also gives us a way to quantify such concentration, in terms of the tail inde
5957

6058
One question of interest is whether or not we can replicate Pareto tails from a relatively simple model.
6159

62-
### A Note on Assumptions
60+
### A note on assumptions
6361

64-
The evolution of wealth for any given household depends on their
65-
savings behavior.
62+
The evolution of wealth for any given household depends on their savings behavior.
6663

6764
Modeling such behavior will form an important part of this lecture series.
6865

69-
However, in this particular lecture, we will be content with rather ad hoc (but plausible) savings rules.
66+
However, in this particular lecture, we will be content with rather *ad hoc* (but plausible) savings rules.
7067

7168
We do this to more easily explore the implications of different specifications of income dynamics and investment returns.
7269

@@ -82,14 +79,13 @@ from numba import jit, float64, prange
8279
from numba.experimental import jitclass
8380
```
8481

85-
## Lorenz Curves and the Gini Coefficient
82+
## Lorenz curves and the Gini coefficient
8683

87-
Before we investigate wealth dynamics, we briefly review some measures of
88-
inequality.
84+
Before we investigate wealth dynamics, we briefly review some measures of inequality.
8985

90-
### Lorenz Curves
86+
### Lorenz curves
9187

92-
One popular graphical measure of inequality is the [Lorenz curve](https://en.wikipedia.org/wiki/Lorenz_curve).
88+
One popular graphical measure of inequality is the **Lorenz curve**.
9389

9490
The package [QuantEcon.py](https://github.com/QuantEcon/QuantEcon.py), already imported above, contains a function to compute Lorenz curves.
9591

@@ -116,21 +112,17 @@ plt.show()
116112

117113
This curve can be understood as follows: if point $(x,y)$ lies on the curve, it means that, collectively, the bottom $(100x)\%$ of the population holds $(100y)\%$ of the wealth.
118114

119-
The "equality" line is the 45 degree line (which might not be exactly 45
120-
degrees in the figure, depending on the aspect ratio).
115+
The "equality" line is the 45 degree line (which might not be exactly 45 degrees in the figure, depending on the aspect ratio).
121116

122-
A sample that produces this line exhibits perfect equality.
117+
A sample that produces this line exhibits **perfect equality**.
123118

124119
The other line in the figure is the Lorenz curve for the lognormal sample, which deviates significantly from perfect equality.
125120

126121
For example, the bottom 80% of the population holds around 40% of total wealth.
127122

128-
Here is another example, which shows how the Lorenz curve shifts as the
129-
underlying distribution changes.
123+
Here is another example, which shows how the Lorenz curve shifts as the underlying distribution changes.
130124

131-
We generate 10,000 observations using the Pareto distribution with a range of
132-
parameters, and then compute the Lorenz curve corresponding to each set of
133-
observations.
125+
We generate 10,000 observations using the Pareto distribution with a range of parameters, and then compute the Lorenz curve corresponding to each set of observations.
134126

135127
```{code-cell} ipython3
136128
a_vals = (1, 2, 5) # Pareto tail index
@@ -150,13 +142,11 @@ You can see that, as the tail parameter of the Pareto distribution increases, in
150142

151143
This is to be expected, because a higher tail index implies less weight in the tail of the Pareto distribution.
152144

153-
### The Gini Coefficient
145+
### The Gini coefficient
154146

155-
The definition and interpretation of the Gini coefficient can be found on the corresponding [Wikipedia page](https://en.wikipedia.org/wiki/Gini_coefficient).
147+
The definition and interpretation of the **Gini coefficient** can be found on the corresponding [Wikipedia page](https://en.wikipedia.org/wiki/Gini_coefficient).
156148

157-
A value of 0 indicates perfect equality (corresponding the case where the
158-
Lorenz curve matches the 45 degree line) and a value of 1 indicates complete
159-
inequality (all wealth held by the richest household).
149+
A value of 0 indicates perfect equality (corresponding the case where the Lorenz curve matches the 45 degree line) and a value of 1 indicates complete inequality (all wealth held by the richest household).
160150

161151
The [QuantEcon.py](https://github.com/QuantEcon/QuantEcon.py) library contains a function to calculate the Gini coefficient.
162152

@@ -166,8 +156,7 @@ $$
166156
G = 1 - 2^{-1/a}
167157
$$
168158

169-
Let's see if the Gini coefficient computed from a simulated sample matches
170-
this at each fixed value of $a$.
159+
Let's see if the Gini coefficient computed from a simulated sample matches this at each fixed value of $a$.
171160

172161
```{code-cell} ipython3
173162
a_vals = range(1, 20)
@@ -190,7 +179,7 @@ plt.show()
190179

191180
The simulation shows that the fit is good.
192181

193-
## A Model of Wealth Dynamics
182+
## A model of wealth dynamics
194183

195184
Having discussed inequality measures, let us now turn to wealth dynamics.
196185

@@ -212,28 +201,26 @@ where
212201
Letting $\{z_t\}$ be a correlated state process of the form
213202

214203
$$
215-
z_{t+1} = a z_t + b + \sigma_z \epsilon_{t+1}
204+
z_{t+1} = a z_t + b + σ_z ε_{t+1}
216205
$$
217206

218207
we’ll assume that
219208

220209
$$
221-
R_t := 1 + r_t = c_r \exp(z_t) + \exp(\mu_r + \sigma_r \xi_t)
210+
R_t := 1 + r_t = c_r \exp(z_t) + \exp(μ_r + σ_r ξ_t)
222211
$$
223212

224213
and
225214

226215
$$
227-
y_t = c_y \exp(z_t) + \exp(\mu_y + \sigma_y \zeta_t)
216+
y_t = c_y \exp(z_t) + \exp(μ_y + σ_y ζ_t)
228217
$$
229218

230-
Here $\{ (\epsilon_t, \xi_t, \zeta_t) \}$ is IID and standard
231-
normal in $\mathbb R^3$.
219+
Here $\{ (ε_t, ξ_t, ζ_t) \}$ is IID and standard normal in $\mathbb R^3$.
232220

233-
The value of $c_r$ should be close to zero, since rates of return
234-
on assets do not exhibit large trends.
221+
The value of $c_r$ should be close to zero, since rates of return on assets do not exhibit large trends.
235222

236-
When we simulate a population of households, we will assume all shocks are idiosyncratic (i.e., specific to individual households and independent across them).
223+
When we simulate a population of households, we will assume all shocks are *idiosyncratic* (i.e., specific to individual households and independent across them).
237224

238225
Regarding the savings function $s$, our default model will be
239226

@@ -245,12 +232,11 @@ s(w) = s_0 w \cdot \mathbb 1\{w \geq \hat w\}
245232

246233
where $s_0$ is a positive constant.
247234

248-
Thus, for $w < \hat w$, the household saves nothing. For
249-
$w \geq \bar w$, the household saves a fraction $s_0$ of
250-
their wealth.
235+
Thus, for $w < \hat w$, the household saves nothing.
251236

252-
We are using something akin to a fixed savings rate model, while
253-
acknowledging that low wealth households tend to save very little.
237+
For $w \geq \bar w$, the household saves a fraction $s_0$ of their wealth.
238+
239+
We are using something akin to a *fixed savings rate model*, while acknowledging that low wealth households tend to save very little.
254240

255241
## Implementation
256242

@@ -346,7 +332,7 @@ class WealthDynamics:
346332
return wp, zp
347333
```
348334

349-
Here's function to simulate the time series of wealth for in individual households.
335+
Here's a function to simulate the time series of wealth for individual households.
350336

351337
```{code-cell} ipython3
352338
@@ -373,7 +359,7 @@ def wealth_time_series(wdy, w_0, n):
373359
return w
374360
```
375361

376-
Now here's function to simulate a cross section of households forward in time.
362+
Now here's a function to simulate a cross section of households forward in time.
377363

378364
Note the use of parallelization to speed up computation.
379365

@@ -406,16 +392,13 @@ def update_cross_section(wdy, w_distribution, shift_length=500):
406392
return new_distribution
407393
```
408394

409-
Parallelization is very effective in the function above because the time path
410-
of each household can be calculated independently once the path for the
411-
aggregate state is known.
395+
Parallelization is very effective in the function above because the time path of each household can be calculated independently once the path for the aggregate state is known.
412396

413397
## Applications
414398

415-
Let's try simulating the model at different parameter values and investigate
416-
the implications for the wealth distribution.
399+
Let's try simulating the model at different parameter values and investigate the implications for the wealth distribution.
417400

418-
### Time Series
401+
### Time series
419402

420403
Let's look at the wealth dynamics of an individual household.
421404

@@ -435,12 +418,11 @@ Notice the large spikes in wealth over time.
435418

436419
Such spikes are similar to what we observed in time series when {doc}`we studied Kesten processes <kesten_processes>`.
437420

438-
### Inequality Measures
421+
### Inequality measures
439422

440423
Let's look at how inequality varies with returns on financial assets.
441424

442-
The next function generates a cross section and then computes the Lorenz
443-
curve and Gini coefficient.
425+
The next function generates a cross section and then computes the Lorenz curve and Gini coefficient.
444426

445427
```{code-cell} ipython3
446428
def generate_lorenz_and_gini(wdy, num_households=100_000, T=500):
@@ -457,7 +439,7 @@ def generate_lorenz_and_gini(wdy, num_households=100_000, T=500):
457439

458440
Now we investigate how the Lorenz curves associated with the wealth distribution change as return to savings varies.
459441

460-
The code below plots Lorenz curves for three different values of $\mu_r$.
442+
The code below plots Lorenz curves for three different values of $μ_r$.
461443

462444
If you are running this yourself, note that it will take one or two minutes to execute.
463445

@@ -475,7 +457,7 @@ gini_vals = []
475457
for μ_r in μ_r_vals:
476458
wdy = WealthDynamics(μ_r=μ_r)
477459
gv, (f_vals, l_vals) = generate_lorenz_and_gini(wdy)
478-
ax.plot(f_vals, l_vals, label=fr'$\psi^*$ at $\mu_r = {μ_r:0.2}$')
460+
ax.plot(f_vals, l_vals, label=fr'$\psi^*$ at $μ_r = {μ_r:0.2}$')
479461
gini_vals.append(gv)
480462
481463
ax.plot(f_vals, f_vals, label='equality')
@@ -485,29 +467,23 @@ plt.show()
485467

486468
The Lorenz curve shifts downwards as returns on financial income rise, indicating a rise in inequality.
487469

488-
We will look at this again via the Gini coefficient immediately below, but
489-
first consider the following image of our system resources when the code above
490-
is executing:
470+
We will look at this again via the Gini coefficient immediately below, but first consider the following image of our system resources when the code above is executing:
491471

492-
Since the code is both efficiently JIT compiled and fully parallelized, it's
493-
close to impossible to make this sequence of tasks run faster without changing
494-
hardware.
472+
Since the code is both efficiently JIT compiled and fully parallelized, it's close to impossible to make this sequence of tasks run faster without changing hardware.
495473

496474
Now let's check the Gini coefficient.
497475

498476
```{code-cell} ipython3
499477
fig, ax = plt.subplots()
500478
ax.plot(μ_r_vals, gini_vals, label='gini coefficient')
501-
ax.set_xlabel(r"$\mu_r$")
479+
ax.set_xlabel(r"$μ_r$")
502480
ax.legend()
503481
plt.show()
504482
```
505483

506-
Once again, we see that inequality increases as returns on financial income
507-
rise.
484+
Once again, we see that inequality increases as returns on financial income rise.
508485

509-
Let's finish this section by investigating what happens when we change the
510-
volatility term $\sigma_r$ in financial returns.
486+
Let's finish this section by investigating what happens when we change the volatility term $σ_r$ in financial returns.
511487

512488

513489
```{code-cell} ipython3
@@ -520,7 +496,7 @@ gini_vals = []
520496
for σ_r in σ_r_vals:
521497
wdy = WealthDynamics(σ_r=σ_r)
522498
gv, (f_vals, l_vals) = generate_lorenz_and_gini(wdy)
523-
ax.plot(f_vals, l_vals, label=fr'$\psi^*$ at $\sigma_r = {σ_r:0.2}$')
499+
ax.plot(f_vals, l_vals, label=fr'$\psi^*$ at $σ_r = {σ_r:0.2}$')
524500
gini_vals.append(gv)
525501
526502
ax.plot(f_vals, f_vals, label='equality')
@@ -535,30 +511,26 @@ We see that greater volatility has the effect of increasing inequality in this m
535511
```{exercise}
536512
:label: wd_ex1
537513
538-
For a wealth or income distribution with Pareto tail, a higher tail index suggests lower inequality.
514+
For a wealth or income distribution with **Pareto tail**, a higher tail index suggests lower inequality.
539515
540-
Indeed, it is possible to prove that the Gini coefficient of the Pareto
541-
distribution with tail index $a$ is $1/(2a - 1)$.
516+
Indeed, it is possible to prove that the **Gini coefficient** of the Pareto distribution with tail index $a$ is $1/(2a - 1)$.
542517
543518
To the extent that you can, confirm this by simulation.
544519
545-
In particular, generate a plot of the Gini coefficient against the tail index
546-
using both the theoretical value just given and the value computed from a sample via `qe.gini_coefficient`.
520+
In particular, generate a plot of the Gini coefficient against the tail index using both the theoretical value just given and the value computed from a sample via `qe.gini_coefficient`.
547521
548522
For the values of the tail index, use `a_vals = np.linspace(1, 10, 25)`.
549523
550524
Use sample of size 1,000 for each $a$ and the sampling method for generating Pareto draws employed in the discussion of Lorenz curves for the Pareto distribution.
551525
552-
To the extent that you can, interpret the monotone relationship between the
553-
Gini index and $a$.
526+
To the extent that you can, interpret the monotone relationship between the Gini index and $a$.
554527
```
555528

556529
```{solution-start} wd_ex1
557530
:class: dropdown
558531
```
559532

560-
Here is one solution, which produces a good match between theory and
561-
simulation.
533+
Here is one solution, which produces a good match between theory and simulation.
562534

563535
```{code-cell} ipython3
564536
a_vals = np.linspace(1, 10, 25) # Pareto tail index
@@ -575,8 +547,7 @@ ax.legend()
575547
plt.show()
576548
```
577549

578-
In general, for a Pareto distribution, a higher tail index implies less weight
579-
in the right hand tail.
550+
In general, for a Pareto distribution, a higher tail index implies less weight in the right hand tail.
580551

581552
This means less extreme values for wealth and hence more equality.
582553

@@ -589,26 +560,25 @@ More equality translates to a lower Gini index.
589560
:label: wd_ex2
590561
```
591562

592-
The wealth process {eq}`wealth_dynam_ah` is similar to a {doc}`Kesten process <kesten_processes>`.
563+
The wealth process {eq}`wealth_dynam_ah` is similar to a **Kesten process**.
593564

594565
This is because, according to {eq}`sav_ah`, savings is constant for all wealth levels above $\hat w$.
595566

596-
When savings is constant, the wealth process has the same quasi-linear
597-
structure as a Kesten process, with multiplicative and additive shocks.
567+
When savings is constant, the wealth process has the same quasi-linear structure as a Kesten process, with multiplicative and additive shocks.
598568

599-
The Kesten--Goldie theorem tells us that Kesten processes have Pareto tails under a range of parameterizations.
569+
The **Kesten--Goldie theorem** tells us that Kesten processes have Pareto tails under a range of parameterizations.
600570

601571
The theorem does not directly apply here, since savings is not always constant and since the multiplicative and additive terms in {eq}`wealth_dynam_ah` are not IID.
602572

603573
At the same time, given the similarities, perhaps Pareto tails will arise.
604574

605-
To test this, run a simulation that generates a cross-section of wealth and
606-
generate a rank-size plot.
575+
To test this, run a simulation that generates a cross-section of wealth and generate a rank-size plot.
607576

608577
If you like, you can use the function `rank_size` from the `quantecon` library (documentation [here](https://quanteconpy.readthedocs.io/en/latest/tools/inequality.html#quantecon.inequality.rank_size)).
609578

610-
In viewing the plot, remember that Pareto tails generate a straight line. Is
611-
this what you see?
579+
In viewing the plot, remember that Pareto tails generate a straight line.
580+
581+
Is this what you see?
612582

613583
For sample size and initial conditions, use
614584

0 commit comments

Comments
 (0)