-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01-read-inputs.R
258 lines (228 loc) · 6.75 KB
/
01-read-inputs.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
### kiernan nicholls
### american university
### spring, 2020
### markets and models
### save and read raw input data
# read market data from https://www.predictit.org/ ------------------------
## Market Data sent by [email protected]
## Detailed price history provided to academic researchers
DailyMarketData <- read_delim(
file = here("data", "raw", "markets", "DailyMarketData.csv"),
delim = "|",
na = "n/a",
col_types = cols(
MarketId = col_character(),
ContractName = col_character(),
ContractSymbol = col_character(),
Date = col_date(format = "")
)
)
Market_ME02 <- read_csv(
file = here("data", "raw", "markets", "Market_ME02.csv"),
col_types = cols(
ContractID = col_character(),
Date = col_date(format = "%m/%d/%Y")
)
)
Contract_NY27 <- read_csv(
file = here("data", "raw", "markets", "Contract_NY27.csv"),
na = c("n/a", "NA"),
skip = 156, # this file was a mess
col_types = cols(
ContractID = col_character(),
Date = col_date(format = "%m/%d/%Y")
)
)
# save member data from https://theunitedstates.io/ -----------------------
# for every file, save raw and read parsed
## Current members of the 115th
## Archived: 2018-10-22 at 18:11
write_memento(
url = "https://theunitedstates.io/congress-legislators/legislators-current.csv",
date = "2018-10-22",
dir = "members"
)
legislators_current <- read_csv(
file = here("data", "raw", "members", "legislators-current.csv"),
col_types = cols(
birthday = col_date(),
govtrack_id = col_character()
)
)
# The ideology and leadership scores of the 115th
# Calculated with cosponsorship analysis
# Archived 2019-01-21 17:13:08
write_memento(
url = "https://www.govtrack.us/data/analysis/by-congress/115/sponsorshipanalysis_h.txt",
date = "2019-03-23",
dir = "members"
)
sponsorshipanalysis_h <- read_csv(
file = here("data", "raw", "members", "sponsorshipanalysis_h.txt"),
col_types = cols(
ID = col_character()
)
)
write_memento(
url = "https://www.govtrack.us/data/analysis/by-congress/115/sponsorshipanalysis_s.txt",
date = "2019-03-23",
dir = "members"
)
sponsorshipanalysis_s <- read_csv(
file = here("data", "raw", "members", "sponsorshipanalysis_s.txt"),
col_types = cols(
ID = col_character()
)
)
# read model and results data from https://fivethirtyeight.com ------------
## District level 538 House model history
## Updated: 2018-11-06 at 01:56
## Archived: 2018-11-06 at 12:06
write_memento(
url = "https://projects.fivethirtyeight.com/congress-model-2018/house_district_forecast.csv",
date = "2018-11-06",
dir = "models"
)
house_district_forecast <- read_csv(
file = here("data", "raw", "models", "house_district_forecast.csv"),
col_types = cols(
forecastdate = col_date(),
state = col_character(),
district = col_double(),
special = col_logical(),
candidate = col_character(),
party = col_character(),
incumbent = col_logical(),
model = col_character(),
win_probability = col_double(),
voteshare = col_double(),
p10_voteshare = col_double(),
p90_voteshare = col_double()
)
)
# Seat level 538 Senate model history
# Updated: 2018-11-06 at 11:06
# Archived: 2018-11-06 at 21:00
write_memento(
url = "https://projects.fivethirtyeight.com/congress-model-2018/senate_seat_forecast.csv",
date = "2018-11-06",
dir = "models"
)
senate_seat_forecast <- read_csv(
file = here("data", "raw", "models", "senate_seat_forecast.csv"),
col_types = cols(
forecastdate = col_date(),
state = col_character(),
class = col_double(),
special = col_logical(),
candidate = col_character(),
party = col_character(),
incumbent = col_logical(),
model = col_character(),
win_probability = col_double(),
voteshare = col_double(),
p10_voteshare = col_double(),
p90_voteshare = col_double()
)
)
# Midterm election results via ABC and 538
# Used in https://53eig.ht/2PiFb0f
# Published: 2018-12-04 at 17:56
# Archived: 2018-04-04 at 16:08
# Midterm election results via ABC and 538
# Used in https://53eig.ht/2PiFb0f
# Published: 2018-12-04 at 17:56
# Archived: 2018-04-04 at 16:08
github_538 <- "https://raw.githubusercontent.com/fivethirtyeight/data/master"
write_memento(
url = paste(github_538, "forecast-review", "forecast_results_2018.csv", sep = "/"),
date = "2019-04-04",
dir = "results"
)
forecast_results <- read_csv(
file = here::here("data", "raw", "results", "forecast_results_2018.csv"),
col_types = cols(
Democrat_Won = col_logical(),
Republican_Won = col_logical(),
uncalled = col_logical(),
forecastdate = col_date(format = "%m/%d/%y"),
category = col_factor(
ordered = TRUE,
levels = c(
"Solid D",
"Likely D",
"Lean D",
"Tossup (Tilt D)",
"Tossup (Tilt R)",
"Lean R",
"Likely R",
"Safe R"
)
)
)
)
# Average difference between how a district votes and the country
# Updated: 2018-11-19 at 16:13
# Archived: 2018-04-04 at 16:05
write_memento(
url = paste(github_538, "partisan-lean", "fivethirtyeight_partisan_lean_DISTRICTS.csv", sep = "/"),
date = "2019-04-04",
dir = "results"
)
partisan_lean_DISTRICTS <- read_csv(
file = here("data", "raw", "results", "fivethirtyeight_partisan_lean_DISTRICTS.csv"),
col_types = cols(
district = col_character(),
pvi_538 = col_character()
)
)
write_memento(
url = paste(github_538, "partisan-lean", "fivethirtyeight_partisan_lean_STATES.csv", sep = "/"),
date = "2019-04-04",
dir = "results"
)
partisan_lean_STATES <- read_csv(
file = here("data", "raw", "results", "fivethirtyeight_partisan_lean_STATES.csv"),
col_types = cols(
state = col_character(),
pvi_538 = col_character()
)
)
# Polls incorperated in the 538 models
# Archived 2019-01-29 at 21:45
poll_cols <- cols(
question_id = col_character(),
poll_id = col_character(),
pollster_id = col_character(),
sponsor_ids = col_character(),
start_date = col_date("%m/%d/%y"),
end_date = col_date("%m/%d/%y"),
created_at = col_datetime("%m/%d/%y %H:%M")
)
write_memento(
url = "https://projects.fivethirtyeight.com/polls-page/senate_polls.csv",
date = "2019-01-29",
dir = "polling"
)
senate_polls <- read_csv(
file = here("data", "raw", "polling", "senate_polls.csv"),
col_types = poll_cols
)
write_memento(
url = "https://projects.fivethirtyeight.com/polls-page/house_polls.csv",
date = "2019-01-29",
dir = "polling"
)
house_polls <- read_csv(
file = here("data", "raw", "polling", "house_polls.csv"),
col_types = poll_cols
)
write_memento(
url = "https://projects.fivethirtyeight.com/polls-page/generic_ballot_polls.csv",
date = "2019-01-29",
dir = "polling"
)
generic_ballot_polls <- read_csv(
file = here("data", "raw", "polling", "generic_ballot_polls.csv"),
col_types = poll_cols
)