{ "cells": [ { "cell_type": "markdown", "id": "5555d096", "metadata": {}, "source": [ "# Wealth Distribution Dynamics" ] }, { "cell_type": "markdown", "id": "2792a797", "metadata": {}, "source": [ "## Contents\n", "\n", "- [Wealth Distribution Dynamics](#Wealth-Distribution-Dynamics) \n", " - [Overview](#Overview) \n", " - [Lorenz Curves and the Gini Coefficient](#Lorenz-Curves-and-the-Gini-Coefficient) \n", " - [A Model of Wealth Dynamics](#A-Model-of-Wealth-Dynamics) \n", " - [Implementation](#Implementation) \n", " - [Applications](#Applications) \n", " - [Exercises](#Exercises) " ] }, { "cell_type": "markdown", "id": "a72c7569", "metadata": {}, "source": [ "A [version of this lecture](https://jax.quantecon.org/wealth_dynamics.html) using a `GPU`\n", "is [available here](https://jax.quantecon.org/wealth_dynamics.html)\n", "\n", "In addition to what’s in Anaconda, this lecture will need the following libraries:" ] }, { "cell_type": "code", "execution_count": null, "id": "f2bfaed4", "metadata": { "hide-output": false }, "outputs": [], "source": [ "!pip install quantecon" ] }, { "cell_type": "markdown", "id": "1e1cb703", "metadata": {}, "source": [ "## Overview\n", "\n", "This notebook gives an introduction to wealth distribution dynamics, with a\n", "focus on\n", "\n", "- modeling and computing the wealth distribution via simulation, \n", "- measures of inequality such as the Lorenz curve and Gini coefficient, and \n", "- how inequality is affected by the properties of wage income and returns on assets. \n", "\n", "\n", "One interesting property of the wealth distribution we discuss is Pareto\n", "tails.\n", "\n", "The wealth distribution in many countries exhibits a Pareto tail\n", "\n", "- See [this lecture](https://intro.quantecon.org/heavy_tails.html) for a definition. \n", "- For a review of the empirical evidence, see, for example, [[Benhabib and Bisin, 2018](https://python.quantecon.org/zreferences.html#id69)]. \n", "\n", "\n", "This is consistent with high concentration of wealth amongst the richest households.\n", "\n", "It also gives us a way to quantify such concentration, in terms of the tail index.\n", "\n", "One question of interest is whether or not we can replicate Pareto tails from a relatively simple model." ] }, { "cell_type": "markdown", "id": "3694627a", "metadata": {}, "source": [ "### A Note on Assumptions\n", "\n", "The evolution of wealth for any given household depends on their\n", "savings behavior.\n", "\n", "Modeling such behavior will form an important part of this lecture series.\n", "\n", "However, in this particular lecture, we will be content with rather ad hoc (but plausible) savings rules.\n", "\n", "We do this to more easily explore the implications of different specifications of income dynamics and investment returns.\n", "\n", "At the same time, all of the techniques discussed here can be plugged into models that use optimization to obtain savings rules.\n", "\n", "We will use the following imports." ] }, { "cell_type": "code", "execution_count": null, "id": "cfd502f0", "metadata": { "hide-output": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "plt.rcParams[\"figure.figsize\"] = (11, 5) #set default figure size\n", "import numpy as np\n", "import quantecon as qe\n", "from numba import njit, float64, prange\n", "from numba.experimental import jitclass" ] }, { "cell_type": "markdown", "id": "9a72e1ef", "metadata": {}, "source": [ "## Lorenz Curves and the Gini Coefficient\n", "\n", "Before we investigate wealth dynamics, we briefly review some measures of\n", "inequality." ] }, { "cell_type": "markdown", "id": "2991e01d", "metadata": {}, "source": [ "### Lorenz Curves\n", "\n", "One popular graphical measure of inequality is the [Lorenz curve](https://en.wikipedia.org/wiki/Lorenz_curve).\n", "\n", "The package [QuantEcon.py](https://github.com/QuantEcon/QuantEcon.py), already imported above, contains a function to compute Lorenz curves.\n", "\n", "To illustrate, suppose that" ] }, { "cell_type": "code", "execution_count": null, "id": "42ef921f", "metadata": { "hide-output": false }, "outputs": [], "source": [ "n = 10_000 # size of sample\n", "w = np.exp(np.random.randn(n)) # lognormal draws" ] }, { "cell_type": "markdown", "id": "3af3cbe9", "metadata": {}, "source": [ "is data representing the wealth of 10,000 households.\n", "\n", "We can compute and plot the Lorenz curve as follows:" ] }, { "cell_type": "code", "execution_count": null, "id": "91d140db", "metadata": { "hide-output": false }, "outputs": [], "source": [ "f_vals, l_vals = qe.lorenz_curve(w)\n", "\n", "fig, ax = plt.subplots()\n", "ax.plot(f_vals, l_vals, label='Lorenz curve, lognormal sample')\n", "ax.plot(f_vals, f_vals, label='Lorenz curve, equality')\n", "ax.legend()\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "995d6f5f", "metadata": {}, "source": [ "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.\n", "\n", "The “equality” line is the 45 degree line (which might not be exactly 45\n", "degrees in the figure, depending on the aspect ratio).\n", "\n", "A sample that produces this line exhibits perfect equality.\n", "\n", "The other line in the figure is the Lorenz curve for the lognormal sample, which deviates significantly from perfect equality.\n", "\n", "For example, the bottom 80% of the population holds around 40% of total wealth.\n", "\n", "Here is another example, which shows how the Lorenz curve shifts as the\n", "underlying distribution changes.\n", "\n", "We generate 10,000 observations using the Pareto distribution with a range of\n", "parameters, and then compute the Lorenz curve corresponding to each set of\n", "observations." ] }, { "cell_type": "code", "execution_count": null, "id": "9a1597f0", "metadata": { "hide-output": false }, "outputs": [], "source": [ "a_vals = (1, 2, 5) # Pareto tail index\n", "n = 10_000 # size of each sample\n", "fig, ax = plt.subplots()\n", "for a in a_vals:\n", " u = np.random.uniform(size=n)\n", " y = u**(-1/a) # distributed as Pareto with tail index a\n", " f_vals, l_vals = qe.lorenz_curve(y)\n", " ax.plot(f_vals, l_vals, label=f'$a = {a}$')\n", "ax.plot(f_vals, f_vals, label='equality')\n", "ax.legend()\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "555bf435", "metadata": {}, "source": [ "You can see that, as the tail parameter of the Pareto distribution increases, inequality decreases.\n", "\n", "This is to be expected, because a higher tail index implies less weight in the tail of the Pareto distribution." ] }, { "cell_type": "markdown", "id": "a743cd0c", "metadata": {}, "source": [ "### The Gini Coefficient\n", "\n", "The definition and interpretation of the Gini coefficient can be found on the corresponding [Wikipedia page](https://en.wikipedia.org/wiki/Gini_coefficient).\n", "\n", "A value of 0 indicates perfect equality (corresponding the case where the\n", "Lorenz curve matches the 45 degree line) and a value of 1 indicates complete\n", "inequality (all wealth held by the richest household).\n", "\n", "The [QuantEcon.py](https://github.com/QuantEcon/QuantEcon.py) library contains a function to calculate the Gini coefficient.\n", "\n", "We can test it on the Weibull distribution with parameter $ a $, where the Gini coefficient is known to be\n", "\n", "$$\n", "G = 1 - 2^{-1/a}\n", "$$\n", "\n", "Let’s see if the Gini coefficient computed from a simulated sample matches\n", "this at each fixed value of $ a $." ] }, { "cell_type": "code", "execution_count": null, "id": "7dfef6d2", "metadata": { "hide-output": false }, "outputs": [], "source": [ "a_vals = range(1, 20)\n", "ginis = []\n", "ginis_theoretical = []\n", "n = 100\n", "\n", "fig, ax = plt.subplots()\n", "for a in a_vals:\n", " y = np.random.weibull(a, size=n)\n", " ginis.append(qe.gini_coefficient(y))\n", " ginis_theoretical.append(1 - 2**(-1/a))\n", "ax.plot(a_vals, ginis, label='estimated gini coefficient')\n", "ax.plot(a_vals, ginis_theoretical, label='theoretical gini coefficient')\n", "ax.legend()\n", "ax.set_xlabel(\"Weibull parameter $a$\")\n", "ax.set_ylabel(\"Gini coefficient\")\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "b880e2d4", "metadata": {}, "source": [ "The simulation shows that the fit is good." ] }, { "cell_type": "markdown", "id": "59b1ea53", "metadata": {}, "source": [ "## A Model of Wealth Dynamics\n", "\n", "Having discussed inequality measures, let us now turn to wealth dynamics.\n", "\n", "The model we will study is\n", "\n", "\n", "\n", "$$\n", "w_{t+1} = (1 + r_{t+1}) s(w_t) + y_{t+1} \\tag{24.1}\n", "$$\n", "\n", "where\n", "\n", "- $ w_t $ is wealth at time $ t $ for a given household, \n", "- $ r_t $ is the rate of return of financial assets, \n", "- $ y_t $ is current non-financial (e.g., labor) income and \n", "- $ s(w_t) $ is current wealth net of consumption \n", "\n", "\n", "Letting $ \\{z_t\\} $ be a correlated state process of the form\n", "\n", "$$\n", "z_{t+1} = a z_t + b + \\sigma_z \\epsilon_{t+1}\n", "$$\n", "\n", "we’ll assume that\n", "\n", "$$\n", "R_t := 1 + r_t = c_r \\exp(z_t) + \\exp(\\mu_r + \\sigma_r \\xi_t)\n", "$$\n", "\n", "and\n", "\n", "$$\n", "y_t = c_y \\exp(z_t) + \\exp(\\mu_y + \\sigma_y \\zeta_t)\n", "$$\n", "\n", "Here $ \\{ (\\epsilon_t, \\xi_t, \\zeta_t) \\} $ is IID and standard\n", "normal in $ \\mathbb R^3 $.\n", "\n", "The value of $ c_r $ should be close to zero, since rates of return\n", "on assets do not exhibit large trends.\n", "\n", "When we simulate a population of households, we will assume all shocks are idiosyncratic (i.e., specific to individual households and independent across them).\n", "\n", "Regarding the savings function $ s $, our default model will be\n", "\n", "\n", "\n", "$$\n", "s(w) = s_0 w \\cdot \\mathbb 1\\{w \\geq \\hat w\\} \\tag{24.2}\n", "$$\n", "\n", "where $ s_0 $ is a positive constant.\n", "\n", "Thus, for $ w < \\hat w $, the household saves nothing. For\n", "$ w \\geq \\bar w $, the household saves a fraction $ s_0 $ of\n", "their wealth.\n", "\n", "We are using something akin to a fixed savings rate model, while\n", "acknowledging that low wealth households tend to save very little." ] }, { "cell_type": "markdown", "id": "064f121e", "metadata": {}, "source": [ "## Implementation\n", "\n", "Here’s some type information to help Numba." ] }, { "cell_type": "code", "execution_count": null, "id": "46a2084d", "metadata": { "hide-output": false }, "outputs": [], "source": [ "wealth_dynamics_data = [\n", " ('w_hat', float64), # savings parameter\n", " ('s_0', float64), # savings parameter\n", " ('c_y', float64), # labor income parameter\n", " ('μ_y', float64), # labor income paraemter\n", " ('σ_y', float64), # labor income parameter\n", " ('c_r', float64), # rate of return parameter\n", " ('μ_r', float64), # rate of return parameter\n", " ('σ_r', float64), # rate of return parameter\n", " ('a', float64), # aggregate shock parameter\n", " ('b', float64), # aggregate shock parameter\n", " ('σ_z', float64), # aggregate shock parameter\n", " ('z_mean', float64), # mean of z process\n", " ('z_var', float64), # variance of z process\n", " ('y_mean', float64), # mean of y process\n", " ('R_mean', float64) # mean of R process\n", "]" ] }, { "cell_type": "markdown", "id": "600bc899", "metadata": {}, "source": [ "Here’s a class that stores instance data and implements methods that update\n", "the aggregate state and household wealth." ] }, { "cell_type": "code", "execution_count": null, "id": "7d4f8e7d", "metadata": { "hide-output": false }, "outputs": [], "source": [ "@jitclass(wealth_dynamics_data)\n", "class WealthDynamics:\n", "\n", " def __init__(self,\n", " w_hat=1.0,\n", " s_0=0.75,\n", " c_y=1.0,\n", " μ_y=1.0,\n", " σ_y=0.2,\n", " c_r=0.05,\n", " μ_r=0.1,\n", " σ_r=0.5,\n", " a=0.5,\n", " b=0.0,\n", " σ_z=0.1):\n", "\n", " self.w_hat, self.s_0 = w_hat, s_0\n", " self.c_y, self.μ_y, self.σ_y = c_y, μ_y, σ_y\n", " self.c_r, self.μ_r, self.σ_r = c_r, μ_r, σ_r\n", " self.a, self.b, self.σ_z = a, b, σ_z\n", "\n", " # Record stationary moments\n", " self.z_mean = b / (1 - a)\n", " self.z_var = σ_z**2 / (1 - a**2)\n", " exp_z_mean = np.exp(self.z_mean + self.z_var / 2)\n", " self.R_mean = c_r * exp_z_mean + np.exp(μ_r + σ_r**2 / 2)\n", " self.y_mean = c_y * exp_z_mean + np.exp(μ_y + σ_y**2 / 2)\n", "\n", " # Test a stability condition that ensures wealth does not diverge\n", " # to infinity.\n", " α = self.R_mean * self.s_0\n", " if α >= 1:\n", " raise ValueError(\"Stability condition failed.\")\n", "\n", " def parameters(self):\n", " \"\"\"\n", " Collect and return parameters.\n", " \"\"\"\n", " parameters = (self.w_hat, self.s_0,\n", " self.c_y, self.μ_y, self.σ_y,\n", " self.c_r, self.μ_r, self.σ_r,\n", " self.a, self.b, self.σ_z)\n", " return parameters\n", "\n", " def update_states(self, w, z):\n", " \"\"\"\n", " Update one period, given current wealth w and persistent\n", " state z.\n", " \"\"\"\n", "\n", " # Simplify names\n", " params = self.parameters()\n", " w_hat, s_0, c_y, μ_y, σ_y, c_r, μ_r, σ_r, a, b, σ_z = params\n", " zp = a * z + b + σ_z * np.random.randn()\n", "\n", " # Update wealth\n", " y = c_y * np.exp(zp) + np.exp(μ_y + σ_y * np.random.randn())\n", " wp = y\n", " if w >= w_hat:\n", " R = c_r * np.exp(zp) + np.exp(μ_r + σ_r * np.random.randn())\n", " wp += R * s_0 * w\n", " return wp, zp" ] }, { "cell_type": "markdown", "id": "4ed0c789", "metadata": {}, "source": [ "Here’s function to simulate the time series of wealth for in individual households." ] }, { "cell_type": "code", "execution_count": null, "id": "f8318fb9", "metadata": { "hide-output": false }, "outputs": [], "source": [ "@njit\n", "def wealth_time_series(wdy, w_0, n):\n", " \"\"\"\n", " Generate a single time series of length n for wealth given\n", " initial value w_0.\n", "\n", " The initial persistent state z_0 for each household is drawn from\n", " the stationary distribution of the AR(1) process.\n", "\n", " * wdy: an instance of WealthDynamics\n", " * w_0: scalar\n", " * n: int\n", "\n", "\n", " \"\"\"\n", " z = wdy.z_mean + np.sqrt(wdy.z_var) * np.random.randn()\n", " w = np.empty(n)\n", " w[0] = w_0\n", " for t in range(n-1):\n", " w[t+1], z = wdy.update_states(w[t], z)\n", " return w" ] }, { "cell_type": "markdown", "id": "eb1c6e11", "metadata": {}, "source": [ "Now here’s function to simulate a cross section of households forward in time.\n", "\n", "Note the use of parallelization to speed up computation." ] }, { "cell_type": "code", "execution_count": null, "id": "667b196b", "metadata": { "hide-output": false }, "outputs": [], "source": [ "@njit(parallel=True)\n", "def update_cross_section(wdy, w_distribution, shift_length=500):\n", " \"\"\"\n", " Shifts a cross-section of household forward in time\n", "\n", " * wdy: an instance of WealthDynamics\n", " * w_distribution: array_like, represents current cross-section\n", "\n", " Takes a current distribution of wealth values as w_distribution\n", " and updates each w_t in w_distribution to w_{t+j}, where\n", " j = shift_length.\n", "\n", " Returns the new distribution.\n", "\n", " \"\"\"\n", " new_distribution = np.empty_like(w_distribution)\n", "\n", " # Update each household\n", " for i in prange(len(new_distribution)):\n", " z = wdy.z_mean + np.sqrt(wdy.z_var) * np.random.randn()\n", " w = w_distribution[i]\n", " for t in range(shift_length-1):\n", " w, z = wdy.update_states(w, z)\n", " new_distribution[i] = w\n", " return new_distribution" ] }, { "cell_type": "markdown", "id": "55797cda", "metadata": {}, "source": [ "Parallelization is very effective in the function above because the time path\n", "of each household can be calculated independently once the path for the\n", "aggregate state is known." ] }, { "cell_type": "markdown", "id": "887d1794", "metadata": {}, "source": [ "## Applications\n", "\n", "Let’s try simulating the model at different parameter values and investigate\n", "the implications for the wealth distribution." ] }, { "cell_type": "markdown", "id": "d0ce2dc7", "metadata": {}, "source": [ "### Time Series\n", "\n", "Let’s look at the wealth dynamics of an individual household." ] }, { "cell_type": "code", "execution_count": null, "id": "0414b7ad", "metadata": { "hide-output": false }, "outputs": [], "source": [ "wdy = WealthDynamics()\n", "ts_length = 200\n", "w = wealth_time_series(wdy, wdy.y_mean, ts_length)" ] }, { "cell_type": "code", "execution_count": null, "id": "7fd2aee8", "metadata": { "hide-output": false }, "outputs": [], "source": [ "fig, ax = plt.subplots()\n", "ax.plot(w)\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "3231f03f", "metadata": {}, "source": [ "Notice the large spikes in wealth over time.\n", "\n", "Such spikes are similar to what we observed in time series when [we studied Kesten processes](https://python.quantecon.org/kesten_processes.html)." ] }, { "cell_type": "markdown", "id": "a7d57818", "metadata": {}, "source": [ "### Inequality Measures\n", "\n", "Let’s look at how inequality varies with returns on financial assets.\n", "\n", "The next function generates a cross section and then computes the Lorenz\n", "curve and Gini coefficient." ] }, { "cell_type": "code", "execution_count": null, "id": "4ec8f055", "metadata": { "hide-output": false }, "outputs": [], "source": [ "def generate_lorenz_and_gini(wdy, num_households=100_000, T=500):\n", " \"\"\"\n", " Generate the Lorenz curve data and gini coefficient corresponding to a\n", " WealthDynamics mode by simulating num_households forward to time T.\n", " \"\"\"\n", " ψ_0 = np.full(num_households, wdy.y_mean)\n", " z_0 = wdy.z_mean\n", "\n", " ψ_star = update_cross_section(wdy, ψ_0, shift_length=T)\n", " return qe.gini_coefficient(ψ_star), qe.lorenz_curve(ψ_star)" ] }, { "cell_type": "markdown", "id": "475960d4", "metadata": {}, "source": [ "Now we investigate how the Lorenz curves associated with the wealth distribution change as return to savings varies.\n", "\n", "The code below plots Lorenz curves for three different values of $ \\mu_r $.\n", "\n", "If you are running this yourself, note that it will take one or two minutes to execute.\n", "\n", "This is unavoidable because we are executing a CPU intensive task.\n", "\n", "In fact the code, which is JIT compiled and parallelized, runs extremely fast relative to the number of computations." ] }, { "cell_type": "code", "execution_count": null, "id": "40c7f4f8", "metadata": { "hide-output": false }, "outputs": [], "source": [ "%%time\n", "\n", "fig, ax = plt.subplots()\n", "μ_r_vals = (0.0, 0.025, 0.05)\n", "gini_vals = []\n", "\n", "for μ_r in μ_r_vals:\n", " wdy = WealthDynamics(μ_r=μ_r)\n", " gv, (f_vals, l_vals) = generate_lorenz_and_gini(wdy)\n", " ax.plot(f_vals, l_vals, label=f'$\\psi^*$ at $\\mu_r = {μ_r:0.2}$')\n", " gini_vals.append(gv)\n", "\n", "ax.plot(f_vals, f_vals, label='equality')\n", "ax.legend(loc=\"upper left\")\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "8df36ae9", "metadata": {}, "source": [ "The Lorenz curve shifts downwards as returns on financial income rise, indicating a rise in inequality.\n", "\n", "We will look at this again via the Gini coefficient immediately below, but\n", "first consider the following image of our system resources when the code above\n", "is executing:\n", "\n", "Since the code is both efficiently JIT compiled and fully parallelized, it’s\n", "close to impossible to make this sequence of tasks run faster without changing\n", "hardware.\n", "\n", "Now let’s check the Gini coefficient." ] }, { "cell_type": "code", "execution_count": null, "id": "a21cd6ff", "metadata": { "hide-output": false }, "outputs": [], "source": [ "fig, ax = plt.subplots()\n", "ax.plot(μ_r_vals, gini_vals, label='gini coefficient')\n", "ax.set_xlabel(\"$\\mu_r$\")\n", "ax.legend()\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "441ce53f", "metadata": {}, "source": [ "Once again, we see that inequality increases as returns on financial income\n", "rise.\n", "\n", "Let’s finish this section by investigating what happens when we change the\n", "volatility term $ \\sigma_r $ in financial returns." ] }, { "cell_type": "code", "execution_count": null, "id": "3aad995d", "metadata": { "hide-output": false }, "outputs": [], "source": [ "%%time\n", "\n", "fig, ax = plt.subplots()\n", "σ_r_vals = (0.35, 0.45, 0.52)\n", "gini_vals = []\n", "\n", "for σ_r in σ_r_vals:\n", " wdy = WealthDynamics(σ_r=σ_r)\n", " gv, (f_vals, l_vals) = generate_lorenz_and_gini(wdy)\n", " ax.plot(f_vals, l_vals, label=f'$\\psi^*$ at $\\sigma_r = {σ_r:0.2}$')\n", " gini_vals.append(gv)\n", "\n", "ax.plot(f_vals, f_vals, label='equality')\n", "ax.legend(loc=\"upper left\")\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "5408c120", "metadata": {}, "source": [ "We see that greater volatility has the effect of increasing inequality in this model." ] }, { "cell_type": "markdown", "id": "b0eeb2a9", "metadata": {}, "source": [ "## Exercises" ] }, { "cell_type": "markdown", "id": "623b317c", "metadata": {}, "source": [ "## Exercise 24.1\n", "\n", "For a wealth or income distribution with Pareto tail, a higher tail index suggests lower inequality.\n", "\n", "Indeed, it is possible to prove that the Gini coefficient of the Pareto\n", "distribution with tail index $ a $ is $ 1/(2a - 1) $.\n", "\n", "To the extent that you can, confirm this by simulation.\n", "\n", "In particular, generate a plot of the Gini coefficient against the tail index\n", "using both the theoretical value just given and the value computed from a sample via `qe.gini_coefficient`.\n", "\n", "For the values of the tail index, use `a_vals = np.linspace(1, 10, 25)`.\n", "\n", "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.\n", "\n", "To the extent that you can, interpret the monotone relationship between the\n", "Gini index and $ a $." ] }, { "cell_type": "markdown", "id": "7d25c525", "metadata": {}, "source": [ "## Solution to[ Exercise 24.1](https://python.quantecon.org/#wd_ex1)\n", "\n", "Here is one solution, which produces a good match between theory and\n", "simulation." ] }, { "cell_type": "code", "execution_count": null, "id": "16c029db", "metadata": { "hide-output": false }, "outputs": [], "source": [ "a_vals = np.linspace(1, 10, 25) # Pareto tail index\n", "ginis = np.empty_like(a_vals)\n", "\n", "n = 1000 # size of each sample\n", "fig, ax = plt.subplots()\n", "for i, a in enumerate(a_vals):\n", " y = np.random.uniform(size=n)**(-1/a)\n", " ginis[i] = qe.gini_coefficient(y)\n", "ax.plot(a_vals, ginis, label='sampled')\n", "ax.plot(a_vals, 1/(2*a_vals - 1), label='theoretical')\n", "ax.legend()\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "8699b441", "metadata": {}, "source": [ "In general, for a Pareto distribution, a higher tail index implies less weight\n", "in the right hand tail.\n", "\n", "This means less extreme values for wealth and hence more equality.\n", "\n", "More equality translates to a lower Gini index." ] }, { "cell_type": "markdown", "id": "0ee96f70", "metadata": {}, "source": [ "## Exercise 24.2\n", "\n", "The wealth process [(24.1)](#equation-wealth-dynam-ah) is similar to a [Kesten process](https://python.quantecon.org/kesten_processes.html).\n", "\n", "This is because, according to [(24.2)](#equation-sav-ah), savings is constant for all wealth levels above $ \\hat w $.\n", "\n", "When savings is constant, the wealth process has the same quasi-linear\n", "structure as a Kesten process, with multiplicative and additive shocks.\n", "\n", "The Kesten–Goldie theorem tells us that Kesten processes have Pareto tails under a range of parameterizations.\n", "\n", "The theorem does not directly apply here, since savings is not always constant and since the multiplicative and additive terms in [(24.1)](#equation-wealth-dynam-ah) are not IID.\n", "\n", "At the same time, given the similarities, perhaps Pareto tails will arise.\n", "\n", "To test this, run a simulation that generates a cross-section of wealth and\n", "generate a rank-size plot.\n", "\n", "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)).\n", "\n", "In viewing the plot, remember that Pareto tails generate a straight line. Is\n", "this what you see?\n", "\n", "For sample size and initial conditions, use" ] }, { "cell_type": "code", "execution_count": null, "id": "b9f0818f", "metadata": { "hide-output": false }, "outputs": [], "source": [ "num_households = 250_000\n", "T = 500 # shift forward T periods\n", "ψ_0 = np.full(num_households, wdy.y_mean) # initial distribution\n", "z_0 = wdy.z_mean" ] }, { "cell_type": "markdown", "id": "b4d9e7aa", "metadata": {}, "source": [ "## Solution to[ Exercise 24.2](https://python.quantecon.org/#wd_ex2)\n", "\n", "First let’s generate the distribution:" ] }, { "cell_type": "code", "execution_count": null, "id": "8f0e4e59", "metadata": { "hide-output": false }, "outputs": [], "source": [ "num_households = 250_000\n", "T = 500 # how far to shift forward in time\n", "wdy = WealthDynamics()\n", "ψ_0 = np.full(num_households, wdy.y_mean)\n", "z_0 = wdy.z_mean\n", "\n", "ψ_star = update_cross_section(wdy, ψ_0, shift_length=T)" ] }, { "cell_type": "markdown", "id": "bf1cc22d", "metadata": {}, "source": [ "Now let’s see the rank-size plot:" ] }, { "cell_type": "code", "execution_count": null, "id": "e4e71cd0", "metadata": { "hide-output": false }, "outputs": [], "source": [ "fig, ax = plt.subplots()\n", "\n", "rank_data, size_data = qe.rank_size(ψ_star, c=0.001)\n", "ax.loglog(rank_data, size_data, 'o', markersize=3.0, alpha=0.5)\n", "ax.set_xlabel(\"log rank\")\n", "ax.set_ylabel(\"log size\")\n", "\n", "plt.show()" ] } ], "metadata": { "date": 1714442511.050518, "filename": "wealth_dynamics.md", "kernelspec": { "display_name": "Python", "language": "python3", "name": "python3" }, "title": "Wealth Distribution Dynamics" }, "nbformat": 4, "nbformat_minor": 5 }