library(janitor)


# before running these lines, set working directory
# to the folder containing atus_0000.xml
# note! your wd will be different than mine!
wd <- "/Users/josh/Google Drive/teaching/dat309/week2/ATUS2"
setwd(wd)

ddi <- read_ipums_ddi("atus_00002.xml")
data <- read_ipums_micro(ddi)

# rename & clean names
data <- data |> rename(job = OCC2_CPS8)
data <- clean_names(data)
data <- rename(data, happy = schappy, stress = scstress)

# filter out non-responses
filter(data, stress < 90) |> 
  ggplot(aes(x = stress)) + geom_bar()

# filter to get some interesting jobs
dmsf <- filter(data,
               job == 120 | job == 122 |job == 132,
                stress < 90)

# first basic atus plot
ggplot(dmsf,aes(x=stress, fill = as_factor(job))) + geom_bar()

# to be super safe
saveRDS(data, file = "atus_data_clean.RDS")



