Skip to content

Instantly share code, notes, and snippets.

@alecperkins
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alecperkins/26dea02df0bf0a08c7ee to your computer and use it in GitHub Desktop.
Save alecperkins/26dea02df0bf0a08c7ee to your computer and use it in GitHub Desktop.

The graph references a paper by Emmanuel Saez that itself references a dataset.

The dataset includes two breakdowns, one including capital gains and one without. The following data is extracted from the capital gains-included set. It also omits the 1913–17 years since those don’t include 90–100 breakdowns.

FIRST_YEAR = 1917

#   0-100   90-100
data = """
    17,167  69,540
    16,226  65,077
    16,094  64,884
    14,354  56,000
    12,536  54,134
    14,318  62,601
    15,937  66,077
    15,862  70,440
    16,469  76,341
    16,460  75,237
    16,735  78,098
    17,616  86,829
    18,165  84,848
    15,680  68,782
    14,016  62,433
    11,704  54,270
    11,554  52,686
    12,614  57,753
    13,797  61,388
    15,385  71,686
    15,752  69,674
    14,555  64,151
    15,463  70,384
    16,171  73,245
    18,906  79,273
    21,860  78,977
    25,439  85,702
    25,142  81,742
    25,083  86,343
    25,533  93,704
    24,252  83,300
    24,624  86,218
    24,148  83,917
    26,392  93,858
    27,114  92,777
    27,811  92,366
    28,904  93,381
    28,864  97,087
    31,120  105,613
    32,590  109,054
    32,468  107,109
    31,651  106,227
    33,894  115,251
    34,031  113,920
    34,851  119,383
    35,652  120,151
    36,629  123,750
    38,589  132,837
    40,473  140,768
    42,072  141,666
    43,592  150,152
    45,505  158,572
    45,460  154,244
    44,783  146,114
    45,096  150,336
    47,294  158,842
    48,037  160,122
    46,122  153,628
    43,664  145,980
    44,957  150,217
    45,445  152,620
    46,312  155,079
    46,828  160,210
    45,429  157,334
    44,922  155,178
    44,130  155,922
    44,370  161,427
    45,921  168,695
    47,191  177,254
    50,568  205,454
    48,179  184,266
    50,612  205,632
    50,178  201,136
    49,250  196,879
    47,606  188,259
    48,140  196,519
    47,713  194,119
    48,451  197,593
    50,071  210,870
    52,048  226,328
    55,059  245,806
    58,409  265,126
    61,175  284,274
    62,730  298,637
    58,381  261,682
    55,374  242,648
    55,054  245,140
    57,870  268,511
    60,410  291,983
    61,998  305,775
    64,287  319,762
    57,920  279,338
    53,082  246,840
    54,190  260,346
    53,781  258,838
    56,271  283,734
"""

Clean and parse the data:

years = data.trim().split('\n').map (year_str) ->
    year_str.trim().split(/\s+/g).map (percentile) ->
        parseInt(percentile.replace(/,/g, ''))

Now the data looks like [ [total, top_10], …]

calc = (start, end) ->
    delta1 = years[start - 1917][1] - years[end - 1917][1]
    delta2 = years[start - 1917][0] - years[end - 1917][0]
    return delta1 / delta2 * 0.1

PERIODS = [
    [1953,1949]
    [1957,1954]
    [1960,1958]
    [1969,1961]
    [1973,1970]
    [1979,1975]
    [1990,1982]
    [2000,1991]
    [2007,2001]
    [2012,2009]
]

@matchChart = (i) ->
    period = PERIODS[i]
    return calc(period[0], period[1])

@growthShare = (year) ->
    unless (PERIODS.some (p) -> p[1] <= year <= p[0])
        return 0
    return calc(year, year - 1)

@contractionShare = (year) ->
    if (PERIODS.some (p) -> p[1] <= year <= p[0])
        return 0
    return calc(year, year - 1)

The original chart

![Matching chart]{bar=matchChart: 0..9}

Share of growth per year

![Per year]{bar=growthShare: 1949..2012}

Share of contraction per year

![Per year]{bar=contractionShare: 1949..2012}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment