Week 3

This table tracks population across different racial categories in each census from 1870 to 1940, this table is meant to illustrate data inconsistencies depending on how data is coded.

Data Source: U.S. Census Bureau (Census Years: 1870, 1880, 1900, 1910, 1920, 1930, 1940)

Data from Alaska and Hawaii Excluded

####Some rows have NA values because of the way enumeration works year to year. Different races are categorized and recorded differently every year. Changes are made to the census or classification all the time. While these changes are indeed noted and coded for by IPUMS, it would neither be appropriate for them to merge racial classifications, nor for me to replace values of NA with 0. This is because the data would subsequently show that there were no people with X race classification for a given year, this is not what the data shows. The data shows it was not counted, not that it did not happen. Replacing an NA with 0 would be showing incorrect data.

library(tidyverse)
library(ipumsr)
library(knitr)





wk3 <- readRDS("wk3.RDS")

wk3 <- wk3 %>% filter(!STATEFIP %in% c(2, 15))

#ipums_val_labels(wk3$RACED)
wk3$RACEDF <- factor(wk3$RACED)

wk3tb =   wk3 %>% group_by(YEAR) %>% count(RACEDF, wt = PERWT) %>% 
          mutate(n = round(n,0) %>% format(big.mark = ",")) %>% spread(YEAR, n)
  

wk3tb$Race = c("White", "Portuguese", "Mexican (1930)", "Puerto Rican", "Black/African American", "Mulatto", "American Indian/Alaska Native (AIAN)", "Chinese", "Japanese", "Filipino", "Asian Indian (Hindu in 1920-1940)", "Korean", "Native Hawaiian", "Other race, n.e.c.")

wk3tb$RACEDF = NULL

wk3tb = wk3tb %>% relocate(Race)


#wk3tb

library("DT")

datatable_obj <- datatable(wk3tb)

#htmlwidgets::saveWidget(datatable_obj, "wk3viz.html")


datatable_obj