GitHub

@@ -96,8 +96,9 @@ The package [QuantEcon.py](https://github.com/QuantEcon/QuantEcon.py), already i

9696

To illustrate, suppose that

97979898

```{code-cell} ipython3

99+

rng = np.random.default_rng()

99100

n = 10_000 # size of sample

100-

w = np.exp(np.random.randn(n)) # lognormal draws

101+

w = np.exp(rng.standard_normal(n)) # lognormal draws

101102

```

102103103104

is data representing the wealth of 10,000 households.

@@ -137,7 +138,7 @@ a_vals = (1, 2, 5) # Pareto tail index

137138

n = 10_000 # size of each sample

138139

fig, ax = plt.subplots()

139140

for a in a_vals:

140-

u = np.random.uniform(size=n)

141+

u = rng.uniform(size=n)

141142

y = u**(-1/a) # distributed as Pareto with tail index a

142143

f_vals, l_vals = qe.lorenz_curve(y)

143144

ax.plot(f_vals, l_vals, label=f'$a = {a}$')

@@ -177,7 +178,7 @@ n = 100

177178178179

fig, ax = plt.subplots()

179180

for a in a_vals:

180-

y = np.random.weibull(a, size=n)

181+

y = rng.weibull(a, size=n)

181182

ginis.append(qe.gini_coefficient(y))

182183

ginis_theoretical.append(1 - 2**(-1/a))

183184

ax.plot(a_vals, ginis, label='estimated gini coefficient')

@@ -561,13 +562,14 @@ Here is one solution, which produces a good match between theory and

561562

simulation.

562563563564

```{code-cell} ipython3

565+

rng = np.random.default_rng()

564566

a_vals = np.linspace(1, 10, 25) # Pareto tail index

565567

ginis = np.empty_like(a_vals)

566568567569

n = 1000 # size of each sample

568570

fig, ax = plt.subplots()

569571

for i, a in enumerate(a_vals):

570-

y = np.random.uniform(size=n)**(-1/a)

572+

y = rng.uniform(size=n)**(-1/a)

571573

ginis[i] = qe.gini_coefficient(y)

572574

ax.plot(a_vals, ginis, label='sampled')

573575

ax.plot(a_vals, 1/(2*a_vals - 1), label='theoretical')

Read the original on github.com ↗