{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "cca528d7",
   "metadata": {},
   "source": [
    "$$\n",
    "\\newcommand{\\argmax}{arg\\,max}\n",
    "\\newcommand{\\argmin}{arg\\,min}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fc6a4338",
   "metadata": {},
   "source": [
    "# Estimating Wealth Tax Revenue"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "42ca8ccc",
   "metadata": {},
   "source": [
    "## Overview\n",
    "\n",
    "In this lecture we discuss an estimation problem that helps to illustrate the\n",
    "value of maximum likelihood methods.\n",
    "\n",
    "The problem is: how much revenue would a tax on the wealth of the very rich raise?\n",
    "\n",
    "This question is topical.\n",
    "\n",
    "For example, in 2019, US Senator Elizabeth Warren proposed an annual tax on household net\n",
    "worth above 50 million dollars, with a higher rate above one billion dollars\n",
    "(see the [proposal](https://elizabethwarren.com/plans/ultra-millionaire-tax)).\n",
    "\n",
    "Emmanuel Saez and Gabriel Zucman estimated that the tax would raise about 2.75\n",
    "trillion dollars over ten years ([letter to\n",
    "Warren](https://www.warren.senate.gov/wp-content/uploads/media/doc/saez-zucman-wealthtax.pdf)),\n",
    "and discuss wealth taxation in detail in [[Saez and Zucman, 2019](https://intro.quantecon.org/zreferences.html#id834)].\n",
    "\n",
    "Other economists argued that these estimates were too high, and much of the\n",
    "disagreement concerned the number and wealth of the very richest households.\n",
    "\n",
    "In this lecture we estimate the revenue from a wealth tax using US household\n",
    "survey data.\n",
    "\n",
    "Estimation is challenging because the richest households are under-represented in the data.\n",
    "\n",
    "To fill the gap we model the upper tail of the wealth distribution with a\n",
    "Pareto distribution, which we fit by [maximum likelihood](https://intro.quantecon.org/mle_intro.html).\n",
    "\n",
    "We will use the following imports."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "58ce0fc5",
   "metadata": {
    "hide-output": false
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "750b9a26",
   "metadata": {},
   "source": [
    "## The tax\n",
    "\n",
    "We study a modification of the Warren proposal, with the following marginal\n",
    "tax rates on household net worth:\n",
    "\n",
    "|Net worth|Marginal rate|\n",
    "|:------------------------------------------------:|:------------------------------------------------:|\n",
    "|up to \\$10 million|0%|\n",
    "|\\$10 million to \\$50 million|1%|\n",
    "|\\$50 million to \\$1 billion|2%|\n",
    "|above \\$1 billion|6%|\n",
    "We can represent this schedule as follows.\n",
    "\n",
    "Let $ h(w) $ be the tax paid by a household with net worth $ w $.\n",
    "\n",
    "We can write $ h $ as\n",
    "\n",
    "\n",
    "<a id='equation-eq-wt-tax'></a>\n",
    "$$\n",
    "h(w) = \\sum_{k=1}^{3} r_k \\, (w - t_k)^+ \\tag{14.1}\n",
    "$$\n",
    "\n",
    "where\n",
    "\n",
    "- $ x^+ = \\max\\{x, 0\\} $,  \n",
    "- the thresholds are $ t_1 = 10\\text{M} $, $ t_2 = 50\\text{M} $ and $ t_3 = 1000\\text{M} $, and  \n",
    "- $ r_1 = 0.01 $, $ r_2 = 0.01 $ and $ r_3 = 0.04 $  \n",
    "\n",
    "\n",
    "Note that each $ r_k $ is the *increment* in the marginal rate at $ t_k $.\n",
    "\n",
    "Here’s how we represent the function in Python."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7b286c2d",
   "metadata": {
    "hide-output": false
   },
   "outputs": [],
   "source": [
    "thresholds = np.array([10e6, 50e6, 1e9])\n",
    "rate_increases = np.array([0.01, 0.01, 0.04])\n",
    "\n",
    "def h(w, thresholds=thresholds, rate_increases=rate_increases):\n",
    "    \"Tax paid by a household with net worth w.\"\n",
    "    return sum(r * np.maximum(w - t, 0)\n",
    "               for t, r in zip(thresholds, rate_increases))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8fd40436",
   "metadata": {},
   "source": [
    "Total revenue is the sum of $ h(w) $ over all households in the country."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8f8c6f2c",
   "metadata": {},
   "source": [
    "## The survey estimate\n",
    "\n",
    "Our data come from the 2022 [Survey of Consumer\n",
    "Finances](https://www.federalreserve.gov/econres/scfindex.htm) (SCF), run by\n",
    "the Federal Reserve Board.\n",
    "\n",
    "The data are a few years old but will be sufficient for this exercise."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "af229f3b",
   "metadata": {
    "hide-output": false
   },
   "outputs": [],
   "source": [
    "url = ('https://github.com/QuantEcon/data-lectures/raw/main/'\n",
    "       'lectures/us_household_net_worth_2022.csv')\n",
    "scf = pd.read_csv(url)\n",
    "scf.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8275ee0e",
   "metadata": {},
   "source": [
    "Each row records the net worth `networth` of a surveyed household and a **survey weight** `wgt`.\n",
    "\n",
    "The weight is the number of US households that the row represents.\n",
    "\n",
    "(The weights are used to adjust for undersampling and oversampling of different parts of the wealth distribution.)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1c9ff52e",
   "metadata": {
    "hide-output": false
   },
   "outputs": [],
   "source": [
    "w = scf['networth'].to_numpy()\n",
    "λ = scf['wgt'].to_numpy()\n",
    "\n",
    "λ.sum() / 1e6     # number of US households, in millions"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4d392aec",
   "metadata": {},
   "source": [
    "One obvious estimate of total revenue is the following weighted sum.\n",
    "\n",
    "$$\n",
    "\\hat T_S = \\sum_i \\lambda_i \\, h(w_i)\n",
    "$$\n",
    "\n",
    "Here $ \\lambda_i $ is the weight of row $ i $."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5daa074c",
   "metadata": {
    "hide-output": false
   },
   "outputs": [],
   "source": [
    "T_survey = np.sum(λ * h(w))\n",
    "print(f\"survey estimate: ${T_survey / 1e9:.0f} billion per year\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e555a78a",
   "metadata": {},
   "source": [
    "## The missing rich\n",
    "\n",
    "By design, the SCF excludes some very rich Americans because such people would be too easy to identify.\n",
    "\n",
    "This means that our estimate is too low.\n",
    "\n",
    "Let’s count the households in the survey above various levels of wealth."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4e5663f5",
   "metadata": {
    "hide-output": false
   },
   "outputs": [],
   "source": [
    "levels = [10e6, 50e6, 100e6, 1e9, 2.7e9]\n",
    "pd.DataFrame({\n",
    "    'survey households': [scf.loc[w > c, 'yy1'].nunique() for c in levels],\n",
    "    'US households represented': [round(λ[w > c].sum()) for c in levels]},\n",
    "    index=['> $10M', '> $50M', '> $100M', '> $1B', '> $2.7B'])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8b6233c6",
   "metadata": {},
   "source": [
    "The survey contains only about twenty households above one billion dollars,\n",
    "and none above 2.7 billion dollars.\n",
    "\n",
    "2.7 billion dollars is exactly the wealth that was needed to make the 2022 Forbes 400\n",
    "list.\n",
    "\n",
    "These individuals were worth a combined 4.0 trillion dollars\n",
    "([Forbes](https://www.forbes.com/sites/chasewithorn/2022/09/27/the-2022-forbes-400-list-of-richest-americans-facts-and-figures/))."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dea8465a",
   "metadata": {
    "hide-output": false
   },
   "outputs": [],
   "source": [
    "forbes_count = 400\n",
    "forbes_cutoff = 2.7e9\n",
    "forbes_wealth = 4.0e12\n",
    "\n",
    "print(f\"total wealth in the survey: ${np.sum(λ * w) / 1e12:.0f} trillion\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bc473618",
   "metadata": {},
   "source": [
    "So, in 2022, the Forbes 400 held about 3% of US household wealth, and all of this wealth is missing from the survey.\n",
    "\n",
    "How much tax would the Forbes 400 pay?\n",
    "\n",
    "We only know their combined wealth, not the wealth of each member, so we cannot\n",
    "simply apply $ h $ to each member.\n",
    "\n",
    "But every member is worth more than one billion dollars, and above that level\n",
    "the tax is simple: a member with wealth $ w $ pays $ h(1\\text{B}) $ on their first\n",
    "billion, plus 6% of the rest.\n",
    "\n",
    "Adding this up over all members gives\n",
    "\n",
    "$$\n",
    "400 \\cdot h(1\\text{B}) + 0.06 \\cdot (\\text{combined wealth} - 400 \\cdot 1\\text{B})\n",
    "$$\n",
    "\n",
    "which depends only on their combined wealth."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "10cc07c3",
   "metadata": {
    "hide-output": false
   },
   "outputs": [],
   "source": [
    "tax_on_first_billion = h(1e9)                # paid in full by every member\n",
    "wealth_above_billion = forbes_wealth - forbes_count * 1e9\n",
    "forbes_tax = forbes_count * tax_on_first_billion + 0.06 * wealth_above_billion\n",
    "print(f\"tax owed by the Forbes 400: ${forbes_tax / 1e9:.0f} billion per year\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "18e04059",
   "metadata": {},
   "source": [
    "This is a large amount relative to the survey estimate, and it is entirely\n",
    "missed by $ \\hat T_S $.\n",
    "\n",
    "There is a second, subtler problem.\n",
    "\n",
    "Even where the survey does contain very rich households, it contains very few\n",
    "of them, so the survey estimate of revenue from the top bracket rests on a\n",
    "handful of observations and is highly uncertain."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "333153ac",
   "metadata": {},
   "source": [
    "## A Pareto model of the upper tail\n",
    "\n",
    "To deal with these problems we need a model of the upper tail of the wealth\n",
    "distribution, which we can estimate from the part of the tail the survey\n",
    "observes and then extend to the part it misses.\n",
    "\n",
    "As discussed in [Heavy-Tailed Distributions](https://intro.quantecon.org/heavy_tails.html), the standard model is the Pareto\n",
    "distribution, going back to Pareto [[1896](https://intro.quantecon.org/zreferences.html#id767)].\n",
    "\n",
    "There is strong empirical support for this choice [[Saez and Zucman, 2016](https://intro.quantecon.org/zreferences.html#id833)],\n",
    "[[Vermeulen, 2018](https://intro.quantecon.org/zreferences.html#id983)].\n",
    "\n",
    "There is also theoretical support: many models in which fortunes grow at\n",
    "random rates generate Pareto upper tails [[Gabaix, 2016](https://intro.quantecon.org/zreferences.html#id375)],\n",
    "[[Jones, 2015](https://intro.quantecon.org/zreferences.html#id545)], [[Benhabib and Bisin, 2018](https://intro.quantecon.org/zreferences.html#id115)].\n",
    "\n",
    "Recall from [Heavy-Tailed Distributions](https://intro.quantecon.org/heavy_tails.html) that if wealth $ W $ has a Pareto tail with tail\n",
    "index α above some threshold $ u $, then\n",
    "\n",
    "$$\n",
    "\\mathbb{P}\\{W > x \\mid W > u\\} = \\left( \\frac{u}{x} \\right)^\\alpha\n",
    "\\qquad (x \\geq u)\n",
    "$$\n",
    "\n",
    "Taking logs, $ \\ln \\mathbb{P}\\{W > x\\} $ is a linear function of $ \\ln x $ with\n",
    "slope $ -\\alpha $.\n",
    "\n",
    "So a Pareto tail shows up as a straight line when we plot the counter CDF (the\n",
    "probability of exceeding $ x $) against $ x $ on log-log axes.\n",
    "\n",
    "Let’s plot the counter CDF of the survey data, using the weights so that each\n",
    "row counts in proportion to the households it represents."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7b6aed97",
   "metadata": {
    "hide-output": false
   },
   "outputs": [],
   "source": [
    "def weighted_ccdf(x_grid, w, λ):\n",
    "    \"Fraction of households with wealth above each point of x_grid.\"\n",
    "    return np.array([λ[w > x].sum() for x in x_grid]) / λ.sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "77ccdd9f",
   "metadata": {
    "hide-output": false
   },
   "outputs": [],
   "source": [
    "x_grid = np.geomspace(1e6, 2.5e9, 300)\n",
    "\n",
    "fig, ax = plt.subplots()\n",
    "ax.loglog(x_grid, weighted_ccdf(x_grid, w, λ), lw=2, label='survey')\n",
    "ax.axvline(10e6, color='k', ls=':', lw=1)\n",
    "ax.set_ylim(1e-8, 1)\n",
    "ax.set_xlabel('net worth (US$)')\n",
    "ax.set_ylabel('fraction of households above')\n",
    "ax.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5fe0a923",
   "metadata": {},
   "source": [
    "Below about 10 million dollars (the dotted line), the curve bends, so the\n",
    "distribution is not Pareto there.\n",
    "\n",
    "Above 10 million dollars it is close to a straight line.\n",
    "\n",
    "At the far right the curve plunges, because the survey data stop just below\n",
    "2.4 billion dollars.\n",
    "\n",
    "We therefore fit a Pareto tail above the threshold $ u = 10 $ million dollars,\n",
    "which is also where our tax begins."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "378ed129",
   "metadata": {},
   "source": [
    "## Estimating the tail index\n",
    "\n",
    "In [Maximum Likelihood Estimation](https://intro.quantecon.org/mle_intro.html) we found that the maximum likelihood estimate of the tail index,\n",
    "given observations $ x_1, \\ldots, x_n $ above a known threshold $ u $, is\n",
    "\n",
    "$$\n",
    "\\hat \\alpha = \\frac{n}{\\sum_{i=1}^n \\ln (x_i / u)}\n",
    "$$\n",
    "\n",
    "Here we have to account for the weights.\n",
    "\n",
    "If row $ i $ represents $ \\lambda_i $ households, then it contributes $ \\lambda_i $\n",
    "copies of its log density to the log likelihood of the population:\n",
    "\n",
    "$$\n",
    "\\ell(\\alpha) = \\sum_{i: w_i > u} \\lambda_i \\ln f(w_i; \\alpha)\n",
    "$$\n",
    "\n",
    "Repeating the calculation in [Maximum Likelihood Estimation](https://intro.quantecon.org/mle_intro.html) with these weights gives\n",
    "\n",
    "$$\n",
    "\\hat \\alpha = \\frac{\\sum_{i: w_i > u} \\lambda_i}\n",
    "                  {\\sum_{i: w_i > u} \\lambda_i \\ln (w_i / u)}\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bbf67bdd",
   "metadata": {
    "hide-output": false
   },
   "outputs": [],
   "source": [
    "def tail_index(u, w, λ):\n",
    "    \"Weighted maximum likelihood estimate of the Pareto tail index above u.\"\n",
    "    above = w > u\n",
    "    return λ[above].sum() / np.sum(λ[above] * np.log(w[above] / u))\n",
    "\n",
    "u = 10e6\n",
    "α_hat = tail_index(u, w, λ)\n",
    "α_hat"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ee438270",
   "metadata": {},
   "source": [
    "This is close to published estimates for the United States, which are around\n",
    "1.5 [[Vermeulen, 2018](https://intro.quantecon.org/zreferences.html#id983)]."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c0b4e0ff",
   "metadata": {},
   "source": [
    "## The Pareto estimate of revenue\n",
    "\n",
    "With the tail estimated, we can compute revenue from the model instead of from\n",
    "the survey.\n",
    "\n",
    "Let $ N_u $ be the number of households with wealth above $ u $, which we estimate\n",
    "from the survey weights."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f47f3037",
   "metadata": {
    "hide-output": false
   },
   "outputs": [],
   "source": [
    "N_u = λ[w > u].sum()\n",
    "N_u"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b8d3dec3",
   "metadata": {},
   "source": [
    "Revenue is $ N_u $ times the average tax paid by a household above $ u $.\n",
    "\n",
    "Using [(14.1)](#equation-eq-wt-tax), this average is\n",
    "\n",
    "$$\n",
    "\\mathbb{E}[h(W) \\mid W > u] = \\sum_{k} r_k \\, \\mathbb{E}[(W - t_k)^+ \\mid W > u]\n",
    "$$\n",
    "\n",
    "For a Pareto tail above $ u $ and a threshold $ t \\geq u $, a short calculation\n",
    "shows that\n",
    "\n",
    "\n",
    "<a id='equation-eq-wt-excess'></a>\n",
    "$$\n",
    "\\mathbb{E}[(W - t)^+ \\mid W > u]\n",
    "= \\int_t^\\infty (x - t) \\, \\frac{\\alpha u^\\alpha}{x^{\\alpha + 1}} \\, dx\n",
    "= \\frac{u^\\alpha t^{1 - \\alpha}}{\\alpha - 1} \\tag{14.2}\n",
    "$$\n",
    "\n",
    "provided that α > 1.\n",
    "\n",
    "(When α ≤ 1 the integral is infinite, so the expected tax is infinite too.)\n",
    "\n",
    "Putting these together gives the Pareto estimate of revenue:\n",
    "\n",
    "$$\n",
    "\\hat T_P = N_u \\sum_k r_k \\frac{u^{\\hat \\alpha} t_k^{1 - \\hat \\alpha}}{\\hat \\alpha - 1}\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d06ca8e0",
   "metadata": {
    "hide-output": false
   },
   "outputs": [],
   "source": [
    "def expected_excess(t, α, u):\n",
    "    \"Expected value of (W - t)^+ for a Pareto tail above u, with t >= u.\"\n",
    "    return u**α * t**(1 - α) / (α - 1)\n",
    "\n",
    "def pareto_revenue(α, u, N_u,\n",
    "                   thresholds=thresholds, rate_increases=rate_increases):\n",
    "    \"Pareto estimate of revenue, for a tail above u containing N_u households.\"\n",
    "    return N_u * np.sum(rate_increases * expected_excess(thresholds, α, u))\n",
    "\n",
    "T_pareto = pareto_revenue(α_hat, u, N_u)\n",
    "print(f\"Pareto estimate: ${T_pareto / 1e9:.0f} billion per year\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "580655e0",
   "metadata": {},
   "source": [
    "## Comparing the two estimates\n",
    "\n",
    "The Pareto estimate is higher than the survey estimate.\n",
    "\n",
    "To see where the difference comes from, let’s break revenue down by bracket.\n",
    "\n",
    "The revenue from bracket $ k $ is the tax on wealth between $ t_k $ and\n",
    "$ t_{k+1} $, at the marginal rate for that bracket."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b0c60ccd",
   "metadata": {
    "hide-output": false
   },
   "outputs": [],
   "source": [
    "marginal_rates = np.cumsum(rate_increases)\n",
    "upper = np.append(thresholds[1:], np.inf)\n",
    "\n",
    "survey_by_bracket = [np.sum(λ * m * np.clip(np.minimum(w, t_up) - t, 0, None))\n",
    "                     for t, t_up, m in zip(thresholds, upper, marginal_rates)]\n",
    "\n",
    "def excess_between(t, t_up, α, u):\n",
    "    \"Expected wealth between t and t_up, for a Pareto tail above u.\"\n",
    "    top = expected_excess(t_up, α, u) if np.isfinite(t_up) else 0.0\n",
    "    return expected_excess(t, α, u) - top\n",
    "\n",
    "pareto_by_bracket = [N_u * m * excess_between(t, t_up, α_hat, u)\n",
    "                     for t, t_up, m in zip(thresholds, upper, marginal_rates)]\n",
    "\n",
    "table = pd.DataFrame({'survey': survey_by_bracket,\n",
    "                      'Pareto': pareto_by_bracket},\n",
    "                     index=['$10M-$50M at 1%', '$50M-$1B at 2%', 'above $1B at 6%'])\n",
    "table.loc['total'] = table.sum()\n",
    "(table / 1e9).round(0)     # billions of dollars per year"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6ace4239",
   "metadata": {},
   "source": [
    "In the first bracket, where the survey has hundreds of households, the two\n",
    "estimates are almost identical.\n",
    "\n",
    "This is reassuring, since it tells us that the Pareto model describes the part\n",
    "of the tail that the survey observes well.\n",
    "\n",
    "The estimates diverge as we move up, and in the top bracket the Pareto\n",
    "estimate is several times larger.\n",
    "\n",
    "This is exactly where the survey is thin and then stops, and where our\n",
    "concern about missing households applies."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "065afa08",
   "metadata": {},
   "source": [
    "## A check against the Forbes 400\n",
    "\n",
    "The Pareto model makes predictions about households that are not in the\n",
    "survey, and we can check them against the Forbes 400.\n",
    "\n",
    "According to the model, the number of households with wealth above the Forbes\n",
    "cutoff $ c = 2.7 $ billion dollars is $ N_u (u / c)^{\\alpha} $.\n",
    "\n",
    "The average wealth of these households is $ \\alpha c / (\\alpha - 1) $, which\n",
    "follows from [(14.2)](#equation-eq-wt-excess) by setting $ u = t = c $ and adding $ c $."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6790761d",
   "metadata": {
    "hide-output": false
   },
   "outputs": [],
   "source": [
    "n_forbes_model = N_u * (u / forbes_cutoff)**α_hat\n",
    "wealth_forbes_model = n_forbes_model * α_hat * forbes_cutoff / (α_hat - 1)\n",
    "\n",
    "pd.DataFrame({'Pareto model': [n_forbes_model, wealth_forbes_model / 1e12],\n",
    "              'Forbes': [forbes_count, forbes_wealth / 1e12]},\n",
    "             index=['households above $2.7B', 'their wealth ($ trillion)']).round(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d6ab5a22",
   "metadata": {},
   "source": [
    "The model predicts somewhat fewer households at this level than Forbes finds,\n",
    "and considerably less wealth, but it gets the orders of magnitude right.\n",
    "\n",
    "This is a demanding test, since the model was estimated entirely from survey\n",
    "households worth less than 2.4 billion dollars.\n",
    "\n",
    "We can see this graphically, by extending the fitted Pareto line beyond the\n",
    "survey data and adding the Forbes 400 as a single point."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "33787b79",
   "metadata": {
    "hide-output": false
   },
   "outputs": [],
   "source": [
    "N = λ.sum()\n",
    "x_fit = np.geomspace(u, 1e11, 100)\n",
    "\n",
    "fig, ax = plt.subplots()\n",
    "ax.loglog(x_grid, weighted_ccdf(x_grid, w, λ), lw=2, label='survey')\n",
    "ax.loglog(x_fit, (N_u / N) * (u / x_fit)**α_hat, 'k--', lw=2,\n",
    "          label='fitted Pareto tail')\n",
    "ax.loglog(forbes_cutoff, forbes_count / N, 'o', ms=8, label='Forbes 400')\n",
    "ax.set_ylim(1e-9, 1)\n",
    "ax.set_xlabel('net worth (US$)')\n",
    "ax.set_ylabel('fraction of households above')\n",
    "ax.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4e2772d7",
   "metadata": {},
   "source": [
    "The Forbes point lies a little above the fitted line.\n",
    "\n",
    "There are several possible reasons.\n",
    "\n",
    "- The estimate of α is uncertain, and a slightly smaller value would pass\n",
    "  through the Forbes point.  \n",
    "- The very top of the distribution may have a heavier tail than the range\n",
    "  from which we estimated α.  \n",
    "- Rich households may be less likely to respond to the survey, which biases\n",
    "  estimates of α upward [[Vermeulen, 2018](https://intro.quantecon.org/zreferences.html#id983)].  \n",
    "- Forbes counts individuals and families using its own valuations, which\n",
    "  differ from the survey’s definition of a household’s net worth.  \n",
    "\n",
    "\n",
    "The comparison suggests that, if anything, our Pareto estimate of revenue is\n",
    "conservative."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fc15f79f",
   "metadata": {},
   "source": [
    "## How much does α matter?\n",
    "\n",
    "The formula for $ \\hat T_P $ contains the term $ \\hat \\alpha - 1 $ in the\n",
    "denominator.\n",
    "\n",
    "So, as α falls toward one, estimated revenue rises without bound.\n",
    "\n",
    "Let’s plot revenue against α."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f16b0cc7",
   "metadata": {
    "hide-output": false
   },
   "outputs": [],
   "source": [
    "α_values = np.linspace(1.3, 2.0, 100)\n",
    "revenue = [pareto_revenue(a, u, N_u) for a in α_values]\n",
    "\n",
    "fig, ax = plt.subplots()\n",
    "ax.plot(α_values, np.array(revenue) / 1e9, lw=2, label='Pareto estimate')\n",
    "ax.axhline(T_survey / 1e9, color='C1', ls='--', lw=2, label='survey estimate')\n",
    "ax.axvline(α_hat, color='k', ls=':', lw=1)\n",
    "ax.set_xlabel(r'tail index $\\alpha$')\n",
    "ax.set_ylabel('revenue (US$ billion per year)')\n",
    "ax.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "902f095f",
   "metadata": {},
   "source": [
    "Moving α from 1.6 to 1.4, a change well within the range of sampling\n",
    "uncertainty (see [this exercise](#wt_ex_bootstrap)), roughly doubles\n",
    "estimated revenue.\n",
    "\n",
    "This sensitivity is one reason why estimates of wealth tax revenue are so\n",
    "contested.\n",
    "\n",
    "Finally, all of our estimates are *mechanical*: they assume that households do\n",
    "not change their behavior in response to the tax.\n",
    "\n",
    "In practice, wealthy households may respond by moving assets, changing how\n",
    "assets are valued, or avoiding the tax in other ways, and the size of these\n",
    "responses is a central question in the policy debate [[Saez and Zucman, 2019](https://intro.quantecon.org/zreferences.html#id834)]."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "99db1f87",
   "metadata": {},
   "source": [
    "## Exercises"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4a5149ff",
   "metadata": {},
   "source": [
    "## Exercise 14.1\n",
    "\n",
    "Warren’s original proposal taxed net worth above 50 million dollars at 2% and\n",
    "net worth above one billion dollars at 3%.\n",
    "\n",
    "Compute the survey estimate and the Pareto estimate of revenue under this\n",
    "schedule.\n",
    "\n",
    "Compare them with the Saez and Zucman estimate of about 275 billion dollars per\n",
    "year (2.75 trillion dollars over ten years)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "09fc2c96",
   "metadata": {},
   "source": [
    "## Solution\n",
    "\n",
    "We pass the new thresholds and rate increases to our functions."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d2d9ccfd",
   "metadata": {
    "hide-output": false
   },
   "outputs": [],
   "source": [
    "warren = dict(thresholds=np.array([50e6, 1e9]),\n",
    "              rate_increases=np.array([0.02, 0.01]))\n",
    "\n",
    "T_s = np.sum(λ * h(w, **warren))\n",
    "T_p = pareto_revenue(α_hat, u, N_u, **warren)\n",
    "print(f\"survey estimate: ${T_s / 1e9:.0f} billion per year\")\n",
    "print(f\"Pareto estimate: ${T_p / 1e9:.0f} billion per year\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7c70a579",
   "metadata": {},
   "source": [
    "Both estimates are of the same magnitude as the Saez and Zucman figure.\n",
    "\n",
    "Their estimate differs from ours in several ways: it covers the years 2019 to\n",
    "2028, uses different data for the top of the distribution, and includes an\n",
    "allowance for tax avoidance.\n",
    "\n",
    "The comparison is therefore only a rough one."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aab187c4",
   "metadata": {},
   "source": [
    "## Exercise 14.2\n",
    "\n",
    "The estimate $ \\hat \\alpha $ is subject to sampling variation.\n",
    "\n",
    "One way to measure this is the **bootstrap**: draw a new sample of households,\n",
    "with replacement, from the survey households, recompute the estimate, and\n",
    "repeat many times.\n",
    "\n",
    "Since each household appears in five rows, resample households (identified by\n",
    "`yy1`) rather than rows.\n",
    "\n",
    "Use 200 bootstrap samples to compute a 90% interval for $ \\hat \\alpha $ at\n",
    "$ u = 10 $ million dollars, and the corresponding interval for $ \\hat T_P $."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4e77b323",
   "metadata": {},
   "source": [
    "## Solution"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "06bcdf29",
   "metadata": {
    "hide-output": false
   },
   "outputs": [],
   "source": [
    "rng = np.random.default_rng(1234)\n",
    "rows_by_household = scf.groupby('yy1').indices\n",
    "households = np.array(list(rows_by_household.keys()))\n",
    "\n",
    "α_boot, T_boot = [], []\n",
    "for _ in range(200):\n",
    "    draw = rng.choice(households, size=len(households))\n",
    "    idx = np.concatenate([rows_by_household[hh] for hh in draw])\n",
    "    w_b, λ_b = w[idx], λ[idx]\n",
    "    a = tail_index(u, w_b, λ_b)\n",
    "    α_boot.append(a)\n",
    "    T_boot.append(pareto_revenue(a, u, λ_b[w_b > u].sum()))\n",
    "\n",
    "print(\"90% interval for α:\", np.percentile(α_boot, [5, 95]).round(2))\n",
    "print(\"90% interval for revenue ($ billion):\",\n",
    "      (np.percentile(T_boot, [5, 95]) / 1e9).round(0))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5100d6d2",
   "metadata": {},
   "source": [
    "The interval for α is roughly ±0.15 around the estimate.\n",
    "\n",
    "The interval for revenue is wide, reflecting the sensitivity to α discussed\n",
    "above."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "825e4cea",
   "metadata": {},
   "source": [
    "## Exercise 14.3\n",
    "\n",
    "The survey estimate and the Pareto estimate agree in the first bracket, where\n",
    "the survey has many observations.\n",
    "\n",
    "This suggests a **hybrid** estimate: use the survey for households below 50\n",
    "million dollars and the Pareto model (still fitted above $ u = 10 $ million\n",
    "dollars) for the rest.\n",
    "\n",
    "Compute it.\n",
    "\n",
    "Hint: a household with wealth $ W > c = 50 $ million dollars pays\n",
    "$ 0.01 (c - 10\\text{ million}) $ on the first bracket, plus\n",
    "$ 0.02 (W - c) + 0.04 (W - 1 \\text{ billion})^+ $."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "51551866",
   "metadata": {},
   "source": [
    "## Solution\n",
    "\n",
    "Averaging the hint over the Pareto tail and multiplying by the number of\n",
    "households, the revenue from households above $ c $ is\n",
    "\n",
    "$$\n",
    "N_c \\cdot 0.01 (c - 10\\text{ million})\n",
    "+ N_u \\left( 0.02 \\, \\mathbb{E}[(W - c)^+ \\mid W > u]\n",
    "            + 0.04 \\, \\mathbb{E}[(W - 1\\text{ billion})^+ \\mid W > u] \\right)\n",
    "$$\n",
    "\n",
    "where $ N_c = N_u (u / c)^\\alpha $ is the number of households above $ c $."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ec6c2f34",
   "metadata": {
    "hide-output": false
   },
   "outputs": [],
   "source": [
    "c = 50e6\n",
    "below = w <= c\n",
    "T_below = np.sum(λ[below] * h(w[below]))\n",
    "\n",
    "N_c = N_u * (u / c)**α_hat\n",
    "T_above = (N_c * 0.01 * (c - 10e6)\n",
    "           + N_u * (0.02 * expected_excess(c, α_hat, u)\n",
    "                    + 0.04 * expected_excess(1e9, α_hat, u)))\n",
    "\n",
    "print(f\"hybrid estimate: ${(T_below + T_above) / 1e9:.0f} billion per year\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "29635d1b",
   "metadata": {},
   "source": [
    "The hybrid estimate lies between the survey and Pareto estimates, and is close\n",
    "to the Pareto estimate, since most of the difference between the two comes from\n",
    "the top brackets."
   ]
  }
 ],
 "metadata": {
  "date": 1795846201.1939762,
  "filename": "wealth_tax.md",
  "kernelspec": {
   "display_name": "Python",
   "language": "python3",
   "name": "python3"
  },
  "title": "Estimating Wealth Tax Revenue"
 },
 "nbformat": 4,
 "nbformat_minor": 5
}