-
Notifications
You must be signed in to change notification settings - Fork 3
/
old_code.R
executable file
·157 lines (155 loc) · 7.93 KB
/
old_code.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
"Biden Therm" = "b_change_biden_therm",
"Voted" = "b_post_did_voteVoted",
"Age" = "b_pre_age",
"BA" = "b_pre_educBachelors",
"HS" = "b_pre_educHighSchool",
"MA" = "b_pre_educMasters",
"Other Ed" = "b_pre_educOther",
"PhD/MBA/JD" = "b_pre_educProfessionalDDoctoral",
"Some College" = "b_pre_educSomeCollege",
"COVID About Right" = "b_pre_fed_response_covidAboutright",
"COVID Too Slow" = "b_pre_fed_response_covidMuchtooslow",
"COVID Somewhat Quick" = "b_pre_fed_response_covidSomewhattooquick",
"COVID Somewhat Slow" = "b_pre_fed_response_covidSomewhattooslow",
"Disabled" = "b_pre_ocupDisabled",
"Homemaker" = "b_pre_ocupHomemaker",
"Retired" = "b_pre_ocupRetired",
"Student" = "b_pre_ocupStudent",
"Unemployed" = "b_pre_ocupUnemployed",
"Asian" = "b_pre_raceAsian",
"Black" = "b_pre_raceBlack",
"Hispanic" = "b_pre_raceHispanic",
"Multiracial" = "b_pre_raceMultiMracial",
"Native American" = "b_pre_raceNativeAmerican",
"Female" = "b_pre_sexFemale",
"Biden Therm" = "change_biden_therm",
"Biden Therm^2" = "b_Ichange_biden_thermE2",
"Voted" = "post_did_voteVoted",
"Age" = "pre_age",
"BA" = "pre_educBachelor's",
"HS" = "pre_educHigh School",
"MA" = "pre_educMaster's",
"Other Ed" = "pre_educOther",
"PhD/MBA/JD" = "pre_educProfessional/Doctoral",
"Some College" = "pre_educSome College",
"COVID About Right" = "pre_fed_response_covidAbout right",
"COVID Too Slow" = "pre_fed_response_covidMuch too slow",
"COVID Somewhat Quick" = "pre_fed_response_covidSomewhat too quick",
"COVID Somewhat Slow" = "pre_fed_response_covidSomewhat too slow",
"Disabled" = "pre_ocupDisabled",
"Homemaker" = "pre_ocupHomemaker",
"Retired" = "pre_ocupRetired",
"Student" = "pre_ocupStudent",
"Unemployed" = "pre_ocupUnemployed",
"Asian" = "pre_raceAsian",
"Black" = "pre_raceBlack",
"Biden Therm^2"="I(change_biden_therm^2)",
"Hispanic" = "pre_raceHispanic",
"Multiracial" = "pre_raceMulti-racial",
"Native American" = "pre_raceNative American",
"Female" = "pre_sexFemale")
group_list=forcats::fct_collapse(variable,
`Biden Therm`=c("Biden Therm","Biden Therm^2"),
Demographics=c("Age",
"Female",
"Black",
"Hispanic","Asian",
"Multiracial",
"Native American"),
`Education\nBaseline=Less Than H.S.`=c("HS",
"Some College",
"BA","MA",
"PhD/MBA/JD",
"Other Ed"),
`Federal Response\nBaseline= Too Quick`=c("COVID About Right","COVID Somewhat Slow","COVID Somewhat Quick","COVID Too Slow"),
`Employment\nBaseline=Employed`=c("Disabled",
"Homemaker", "Retired","Student","Unemployed")))
# anes <- read_csv("data/anes_timeseries_2020_csv_20210719/anes_timeseries_2020_csv_20210719.csv") %>%
# select(pre_vote_choice_2020="V201029",
# pre_pref_strong="V201030",
# pre_intend_vote_2020="V201032",
# pre_intend_vote_choice_2020="V201033",
# pre_did_vote_2016="V201101",
# pre_country_on_track="V201114",
# pre_afraid="V201116",
# pre_angry="V201118",
# pre_worry="V201120",
# pre_sex="V201600",
# pre_pres_approval="V201129x",
# handle_covid="V201144x",
# pre_biden_therm="V201151",
# pre_trump_therm="V201152",
# pre_ideology="V201200",
# pre_party_id="V201231x",
# pre_trust_gov="V201233",
# pre_party_covid="V201244",
# pre_econ_worry="V201335",
# pre_trust_news="V201377",
# pre_fed_response_covid="V201392x",
# pre_age="V201507x",
# pre_marital_status="V201508",
# pre_educ="V201510",
# pre_ocup="V201534x",
# pre_race="V201549x",
# post_party_contact="V202005",
# post_give_money="V202017",
# post_discuss_pol="V202023",
# post_discuss_pol_online="V202029",
# post_asian_therm="V202477",
# post_did_vote="V202109x",
# post_biden_therm="V202143",
# post_who_voted="V202110x",
# pre_date="V203053") %>%
# mutate_all(~ifelse(. %in% c(998,-1:-10),NA,.))
#
# # clean data
#
# model_data_long <- mutate(anes,
# change_biden_therm=scale(post_biden_therm - pre_biden_therm)[,1],
# asian_scale=post_asian_therm/100,
# therm=floor(post_asian_therm)/100,
# therm_rescale=(therm * (sum(!is.na(therm))-1) + 0.5)/sum(!is.na(therm)),
# #therm=floor(post_biden_therm)/100,
# #therm_rescale=(therm * (sum(!is.na(therm))-1) + 0.5)/sum(!is.na(therm)),
# pre_sex=factor(pre_sex,labels=c("Male","Female")),
# pre_age=pre_age/10,
# pre_educ=factor(pre_educ,
# labels=c("<High School",
# "High School",
# "Some College",
# "Associate Vocational",
# "Associate Academic",
# "Bachelor's",
# "Master's",
# "Professional/Doctoral",
# "Other")),
# pre_educ=fct_collapse(pre_educ,
# `Some College`=c("Associate Vocational",
# "Associate Academic",
# "Some College")),
# pre_ocup=factor(pre_ocup,labels=c("Employed",
# "Laid Off",
# "Unemployed",
# "Retired",
# "Disabled",
# "Homemaker",
# "Student")),
# pre_ocup=fct_collapse(pre_ocup,Unemployed=c("Laid Off",
# "Unemployed")),
# post_did_vote=factor(post_did_vote,
# labels=c("Did not vote",
# "Voted")),
# pre_race=factor(pre_race,
# labels=c("White",
# "Black",
# "Hispanic",
# "Asian",
# "Native American",
# "Multi-racial")),
# pre_fed_response_covid=factor(pre_fed_response_covid,
# labels=c("Much too quick",
# "Somewhat too quick",
# "About right",
# "Somewhat too slow",
# "Much too slow")),
# therm_type=case_when(therm>0 & therm<1 ~ "inside",therm==0|therm==1~"outside",TRUE~'other'))