Skip to content

Instantly share code, notes, and snippets.

@HughParsonage
Created January 31, 2018 07:30
Show Gist options
  • Save HughParsonage/88806402528cfa4709d0ad35d42dd11f to your computer and use it in GitHub Desktop.
Save HughParsonage/88806402528cfa4709d0ad35d42dd11f to your computer and use it in GitHub Desktop.
library(data.table)
library(magrittr)
library(grattan)
library(SampleFile1415)
library(taxstats)
library(hutils)
library(scales)
tax2014 <- copy(sample_file_1415) %>% apply_super_caps_and_div293()
nIndivsPreTaxContrGeq10K_by_decile <-
tax2014[, .(nIndivsPreTaxContrGeq10K = 50L * sum(concessional_contributions > 10e3),
nIndivsVoluntaryContrGeq10K = 50L * sum(concessional_contributions - SG_contributions > 10e3)),
keyby = .(TaxableIncomeDecile = factor(dplyr::ntile(Taxable_Income, 10L)),
Gender)] %>%
melt.data.table(measure.vars = patterns("10K")) %>%
.[, Sex := if_else(as.logical(Gender), "Female", "Male")] %>%
.[]
library(grattanCharts)
library(ggplot2)
grplot(nIndivsPreTaxContrGeq10K_by_decile,
aes(x = TaxableIncomeDecile,
y = value,
fill = variable)) +
geom_col(position = "dodge") +
facet_wrap(~Sex) +
xlab("Taxable Income decile") +
scale_y_continuous(labels = comma)
tax201718 <- project(sample_file_1415, h = 3L) %>% apply_super_caps_and_div293()
sample_file_1415 %>%
copy %>%
.[, in_scope := MCS_Ttl_Acnt_Bal > 500e3] %>%
project(h = 3L) %>%
apply_super_caps_and_div293() %>%
.[, TaxableIncomeDecile := factor(dplyr::ntile(Taxable_Income, 10L))] %>%
.[(in_scope)] %>%
.[, .(N = floor(sum(WEIGHT * (concessional_contributions > 25e3)))),
keyby = .(Sex = if_else(as.logical(Gender), "Female", "Male"),
TaxableIncomeDecile)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment