Additional datasets: Annual T1FF taxfiler data

Dataset background and example usage

Background

Through collaboration with the Canadian Mortgage and Housing Corporation (CMHC), CensusMapper has added and open-sourced annual T1FF taxfiler data which provides an annual look at some basic demographic variables. Data is available via the cancensus package for the years 2001 through 2017. The T1FF dataset contains information on:

The data comes in varying Census geographies, depending on the year. Retrieving any annual dataset via get_census will automatically reference to the correct Census geography and attach the correct spatial boundaries.

The taxfiler data is organized with consistent internal referencing. The identifier for the number of families in low income in 2017 is “v_TX2017_786” and that for all families is “v_TX2017_607”, and the ones for the other years are given by simply swapping out the year. This makes the variables selection process easy.

Example usage: constructing a multi-year series of families in low-income status

As an example we will explore a multi-year time series for families in low income. Data on low income families is available for years 2004 and later, we will start with 2006 just so that the data fits on a nice grid.

# Packages used for example
library(cancensus)
library(dplyr)
library(tidyr)
library(ggplot2)
library(sf)

To see all available T1FF datasets and their reference codes we can use list_census_datasets().

list_census_datasets() %>% 
  filter(grepl("taxfiler",description))
#> # A tibble: 19 × 6
#>    dataset description   geo_dataset attribution    reference reference_url     
#>    <chr>   <chr>         <chr>       <chr>          <chr>     <chr>             
#>  1 TX2000  2000 T1FF ta… CA1996      StatCan 2000 … 72-212-X  https://www150.st…
#>  2 TX2001  2001 T1FF ta… CA01        StatCan 2001 … 72-212-X  https://www150.st…
#>  3 TX2002  2002 T1FF ta… CA01        StatCan 2002 … 72-212-X  https://www150.st…
#>  4 TX2003  2003 T1FF ta… CA01        StatCan 2003 … 72-212-X  https://www150.st…
#>  5 TX2004  2004 T1FF ta… CA01        StatCan 2004 … 72-212-X  https://www150.st…
#>  6 TX2005  2005 T1FF ta… CA01        StatCan 2005 … 72-212-X  https://www150.st…
#>  7 TX2006  2006 T1FF ta… CA06        StatCan 2006 … 72-212-X  https://www150.st…
#>  8 TX2007  2007 T1FF ta… CA06        StatCan 2007 … 72-212-X  https://www150.st…
#>  9 TX2008  2008 T1FF ta… CA06        StatCan 2008 … 72-212-X  https://www150.st…
#> 10 TX2009  2009 T1FF ta… CA06        StatCan 2009 … 72-212-X  https://www150.st…
#> 11 TX2010  2010 T1FF ta… CA06        StatCan 2010 … 72-212-X  https://www150.st…
#> 12 TX2011  2011 T1FF ta… CA06        StatCan 2011 … 72-212-X  https://www150.st…
#> 13 TX2012  2012 T1FF ta… CA11        StatCan 2012 … 72-212-X  https://www150.st…
#> 14 TX2013  2013 T1FF ta… CA11        StatCan 2013 … 72-212-X  https://www150.st…
#> 15 TX2014  2014 T1FF ta… CA11        StatCan 2014 … 72-212-X  https://www150.st…
#> 16 TX2015  2015 T1FF ta… CA11        StatCan 2015 … 72-212-X  https://www150.st…
#> 17 TX2016  2016 T1FF ta… CA16        StatCan 2016 … 72-212-X  https://www150.st…
#> 18 TX2017  2017 T1FF ta… CA16        StatCan 2017 … 72-212-X  https://www150.st…
#> 19 TX2018  2018 T1FF ta… CA16        StatCan 2018 … 72-212-X  https://www150.st…

And, as an example, available data vectors for one such T1FF dataset.

list_census_vectors('TX2017')
#> # A tibble: 818 × 7
#>    vector      type  label           units  parent_vector aggregation details   
#>    <chr>       <fct> <chr>           <fct>  <chr>         <chr>       <chr>     
#>  1 v_TX2017_1  Total Taxfilers - #   Number <NA>          Additive    Tax data …
#>  2 v_TX2017_3  Total % 0-24          Perce… v_TX2017_1    Average of… Tax data …
#>  3 v_TX2017_4  Total % 25-44         Perce… v_TX2017_1    Average of… Tax data …
#>  4 v_TX2017_5  Total % 45-64         Perce… v_TX2017_1    Average of… Tax data …
#>  5 v_TX2017_6  Total % 65+           Perce… v_TX2017_1    Average of… Tax data …
#>  6 v_TX2017_7  Total Average - Age   Ratio  v_TX2017_1    Average of… Tax data …
#>  7 v_TX2017_8  Total % female        Perce… v_TX2017_1    Average of… Tax data …
#>  8 v_TX2017_9  Total % married       Perce… v_TX2017_1    Average of… Tax data …
#>  9 v_TX2017_10 Total % in appt       Perce… v_TX2017_1    Average of… Tax data …
#> 10 v_TX2017_11 Total All persons - # Number <NA>          Additive    Tax data …
#> # … with 808 more rows

This particular dataset has over 800 individual vectors. The vector codes follow a regular pattern across different years, and we can use this to quickly identify all the relevant variables of interest across multiple datasets. We can utilized the CensusMapper gaphical variable selection interface, which can also be reached by calling explore_census_vectors() from the R console. For this example we are interested in low income families and note that the internal CensusMapper vector for all families is of the form *v_TX_607* and that for all families in low income is *v_TX_786*.

While the geography varies across Census periods, the call to get_census will automatically attach the correct geography for each annual dataset. We pick four years to look at low income families.

years <- c(2006,2011,2014,2018)
# Attribution for the dataset to be used in graphs
attribution <- dataset_attribution(paste0("TX",years))

plot_data <- years %>%
  lapply(function(year) {
    dataset <- paste0("TX",year)
    vectors <- c("Families"=paste0("v_",dataset,"_607"),
                 "CFLIM-AT"=paste0("v_",dataset,"_786"))
    
    get_census(dataset,regions=list(CMA="59933"),vectors = vectors,
                    geo_format = 'sf', level="CT", quiet = TRUE) %>%
      select(c("GeoUID",names(vectors))) %>%
      mutate(Year=year)
  }) %>%
  bind_rows() %>%
  mutate(share=`CFLIM-AT`/Families)

Here we also re-organized the data by year. All that’s left is to plot the data, one year at a time.

ggplot(plot_data,aes(fill=share)) +
  geom_sf(size=0.1,color="white") +
  facet_wrap("Year") +
  scale_fill_viridis_c(labels=scales::percent,option = "inferno",
                       trans="log",breaks = c(0.05,0.1,0.2,0.4)) +
  coord_sf(datum=NA,xlim=c(-123.4, -122.5), ylim=c(49.01, 49.4)) +
  labs(title="Share of census families in low income",fill="Share",
       caption=attribution)

We may be tempted to re-arrange the data to create timelines, but we have to be careful as census geographies change over time. Inspecting the dataset tables at the top informs us that the 2006 through 2011 data all come on the common 2006 census geography, so the 2006 and 2011 tax data are directly comparable.

change_data <- plot_data %>% 
  filter(Year==2006) %>% 
  select(GeoUID,`2006`=share) %>%
  left_join(plot_data %>%
              st_set_geometry(NULL) %>%
              filter(Year==2011) %>% 
              select(GeoUID,`2011`=share),
            by="GeoUID") %>%
  mutate(change=`2011`-`2006`)
  
ggplot(change_data,aes(fill=change)) +
  geom_sf(size=0.1) +
  scale_fill_gradient2(labels=scales::percent) +
  #scale_fill_viridis_c(labels=scales::percent,option = "inferno") +
  coord_sf(datum=NA,xlim=c(-123.4, -122.5), ylim=c(49.01, 49.4)) +
  labs(title="Change in share of census families in low income 2006-2011",fill="Percentage\npoint change",caption=dataset_attribution(paste0("TX",c(2006,2011))))

Analyzing change over longer timelines that span changes in Census geometries involves more work, the tongfen package facilitates this and provides a convenient interface for generating timelines spanning geometries from several Census years.