Skip to content

Instantly share code, notes, and snippets.

@HughParsonage
Last active November 5, 2018 05:13
Show Gist options
  • Save HughParsonage/7651a555b9e81f6b72369034fab51e22 to your computer and use it in GitHub Desktop.
Save HughParsonage/7651a555b9e81f6b72369034fab51e22 to your computer and use it in GitHub Desktop.
Average income tax by age 2015-15 vs 2003-04 (in 2015-16 dollars)
library(data.table)
library(grattan)
library(hutils)
library(magrittr)
library(ggplot2)
RQ("grattanCharts",
devtools::install_github("hughparsonage/grattanCharts"))
library(grattanCharts) # hughparsonage/grattanCharts
RQ("taxstats",
install.packages("taxstats",
repos = "https://hughparsonage.github.io/tax-drat/",
type = "source"))
RQ("taxstats1516",
install.packages("taxstats",
repos = "https://hughparsonage.github.io/tax-drat/",
type = "source"))
library(taxstats) # hughparsonage/taxstats
library(taxstats1516) # hughparsonage/taxstats1516
sample_file_1415 <- copy(taxstats::sample_file_1415_synth)
sample_file_1516 <- copy(taxstats1516::sample_file_1516_synth)
sample_file_1415[, fy.year := "2014-15"]
sample_file_1516[, fy.year := "2015-16"]
sfa <-
list(get_sample_files_all(),
copy(sample_file_1415)[, fy.year := "2014-15"],
sample_file_1516) %>%
rbindlist(use.names = TRUE,
fill = TRUE) %>%
.[, WEIGHT := coalesce(WEIGHT, 50L)] %>%
.[, WEIGHT := as.double(WEIGHT)] %>%
.[, age_range := coalesce(age_range, Birth_year)] %>%
.[age_range_decoder, on = "age_range"] %>%
.[, Age.min := 70 - 5 * age_range] %>%
mutate_ntile("Taxable_Income",
n = 100L,
weights = "WEIGHT",
keyby = "fy.year",
character.only = TRUE) %>%
.[, CPI_rel_201819 := cpi_inflator(from_fy = fy.year, to_fy = "2017-18")] %>%
.[, tax := income_tax(Taxable_Income, fy.year = .BY[[1L]], .dots.ATO = .SD), keyby = "fy.year"] %>%
.[, taxNoAge := income_tax(Taxable_Income, fy.year = .BY[[1L]], .dots.ATO = .SD, age = 42), keyby = "fy.year"] %>%
.[, real_tax := tax * CPI_rel_201819] %>%
.[, real_taxNoAge := taxNoAge * CPI_rel_201819] %>%
.[]
sfa %>%
.[, .(avgTax = mean(real_tax)),
keyby = c("fy.year", "Age.min")] %>%
.[, change := avgTax - avgTax[fy.year == "2003-04"], keyby = "Age.min"] %>%
.[, Year := fy2yr(fy.year)] %>%
.[Year == 2016L] %>%
.[, Age := Age.min + 2L] %>% # cosmetic
grplot(aes(x = Age, y = change)) +
geom_bar(stat = "identity") +
scale_y_continuous(label = grattan_dollar) +
theme(legend.position = "right",
legend.title = element_blank())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment