-
Notifications
You must be signed in to change notification settings - Fork 1
/
04_prepare-fixes.R
79 lines (62 loc) · 2.63 KB
/
04_prepare-fixes.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# subsets to fix in 02
library(tidyverse)
library(dplyr)
library(haven)
load("data/output/01_responses/common_all.RData")
# Retrieve 2007 County -----
# Retrieve 2010 PID -------
pid3_cc10 <- cc10 |>
mutate(pid3 = V212a) |>
mutate(
pid3_char = as.character(as_factor(pid3)),
pid3_num = as.numeric(pid3)
) |>
mutate(
pid3_char = replace(pid3_char, pid3_char == "NaN", NA),
pid3_num = replace(pid3_num, is.nan(pid3_num), NA)
) |>
select(year, case_id, pid3_char, pid3_num)
# 2009 Economic retrospective recode
econ_recoded <- cc09 |>
select(year, case_id, cc09_20) |>
mutate(economy_retro_num = recode(as.integer(haven::zap_labels(cc09_20)),
`1` = 5L, `2` = 4L, `3` = 3L, `4` = 2L, `5` = 1L)) |>
mutate(economy_retro_char = case_when(economy_retro_num == 5L ~ "Gotten Much Worse",
economy_retro_num == 4L ~ "Gotten Worse / Somewhat Worse",
economy_retro_num == 3L ~ "Stayed About The Same",
economy_retro_num == 2L ~ "Gotten Better / Somewhat Better",
economy_retro_num == 1L ~ "Gotten Much Better"
)) |>
select(-cc09_20)
# date time in 2006 and 2009 ----
fmt_date <- function(vec) {
as.POSIXct(vec, format = "%a %b %e %T %Y")
}
cc06_time <- cc06 |>
mutate(starttime = fmt_date(starttime)) |>
select(year, case_id, starttime) |>
bind_rows(select(mit06_add, year, case_id, starttime))
cc09_time <- cc09 |>
mutate(starttime = as.POSIXct(v401)) |>
select(year, case_id, starttime)
# recode newsinterest to fit with 2008 - 2018
cc06_interest <- cc06 |>
transmute(year,
case_id,
interest = as.integer(v2042))
# save ---------
write_rds(pid3_cc10, "data/output/01_responses/cc10_pid3.Rds")
write_rds(econ_recoded, "data/output/01_responses/cc09_econ_retro.Rds")
write_rds(cc06_time, "data/output/01_responses/cc06_datetime.Rds")
write_rds(cc09_time, "data/output/01_responses/cc09_datetime.Rds")
write_rds(cc06_interest, "data/output/01_responses/cc06_newsintnum.Rds")
# fs::file_copy("data/output/01_responses/cc06_newsintnum.Rds",
# "~/Dropbox/CCES_representation/data/output/intermediate", overwrite = TRUE)
# 2009 split sample distinction
if (FALSE) {
p09_recontact <- read_dta("~/Dropbox/CCES_SDA/2009/Data/HUM/cces09_harvard_recontact_output.dta") %>%
mutate(year = 2009, samp = "recontact", case_id = v100) %>%
select(year, samp, everything()) %>%
select(-case_id)
write_dta(p09_recontact, "data/source/cces/2009_hum_recontact.dta")
}