-
Notifications
You must be signed in to change notification settings - Fork 0
/
FEC Previous Cycles.Rmd
199 lines (159 loc) · 9.15 KB
/
FEC Previous Cycles.Rmd
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
---
title: "R Notebook"
output: html_notebook
---
Individual Donations
```{r}
# individual donations header
ind_header <- t((fread("input data/FEC/Individual/indiv_header_file.csv", header=FALSE)))
# individual donations 2012
ind_12 <- read.table("input data/FEC/Individual/indiv12/itcont.txt", header=FALSE, sep = '|', fill = TRUE, quote = "", col.names = ind_header[,1]) %>%
filter(str_sub(toString(TRANSACTION_DT), -4, -1) == "2012") %>%
select(TRAN_ID, TRANSACTION_DT, TRANSACTION_AMT, CMTE_ID, STATE)
head(ind_12)
# individual donations 2014
ind_14 <- read.table("input data/FEC/Individual/indiv14/itcont.txt", header=FALSE, sep = '|', fill = TRUE, quote = "", col.names = ind_header[,1]) %>%
filter(str_sub(toString(TRANSACTION_DT), -4, -1) == "2014") %>%
select(TRAN_ID, TRANSACTION_DT, TRANSACTION_AMT, CMTE_ID, STATE)
head(ind_14)
# individual donations 2016
ind_16 <- read.table("input data/FEC/Individual/indiv16/itcont.txt", header=FALSE, sep = '|', fill = TRUE, quote = "", col.names = ind_header[,1]) %>%
filter(str_sub(toString(TRANSACTION_DT), -4, -1) == "2016") %>%
select(TRAN_ID, TRANSACTION_DT, TRANSACTION_AMT, CMTE_ID, STATE)
head(ind_16)
# individual donations 2018
ind_18 <- read.table("input data/FEC/Individual/indiv18/itcont.txt", header=FALSE, sep = '|', fill = TRUE, quote = "", col.names = ind_header[,1]) %>%
filter(str_sub(toString(TRANSACTION_DT), -4, -1) == "2018") %>%
select(TRAN_ID, TRANSACTION_DT, TRANSACTION_AMT, CMTE_ID, STATE)
head(ind_18)
# individual donations 2020
ind_20 <- read.table("input data/FEC/Individual/indiv20/itcont.txt", header=FALSE, sep = '|', fill = TRUE, quote = "", col.names = ind_header[,1]) %>%
filter(str_sub(toString(TRANSACTION_DT), -4, -1) == "2020") %>%
select(TRAN_ID, TRANSACTION_DT, TRANSACTION_AMT, CMTE_ID, STATE)
head(ind_20)
# individual donations 2022
ind_22 <- read.table("input data/FEC/Individual/indiv22/itcont.txt", header=FALSE, sep = '|', fill = TRUE, quote = "", col.names = ind_header[,1]) %>%
filter(str_sub(toString(TRANSACTION_DT), -4, -1) == "2022") %>%
select(TRAN_ID, TRANSACTION_DT, TRANSACTION_AMT, CMTE_ID, STATE)
head(ind_22)
```
FEC Candidates
```{r}
# candidate header
cn_header <- t((fread("input data/FEC/Candidates/cn_header_file.csv", header=FALSE)))
# candidates 2012
cn_12 <- read.table("input data/FEC/Candidates/cn12.txt", header=FALSE, sep = '|', fill = TRUE, quote = "", col.names = cn_header[,1]) %>%
filter(CAND_ELECTION_YR == 2012 & (CAND_OFFICE == "H" | CAND_OFFICE == "S") & (CAND_PTY_AFFILIATION == "REP" | CAND_PTY_AFFILIATION == "DEM")) %>%
select(CAND_ID, CAND_NAME, CAND_PTY_AFFILIATION, CAND_ELECTION_YR, CAND_OFFICE, CAND_OFFICE_ST, CAND_OFFICE_DISTRICT, CAND_PCC)
head(cn_12)
write.csv(cn_12, "output data/FEC Candidates/cn_12.csv")
# candidates 2014
cn_14 <- read.table("input data/FEC/Candidates/cn14.txt", header=FALSE, sep = '|', fill = TRUE, quote = "", col.names = cn_header[,1]) %>%
filter(CAND_ELECTION_YR == 2014 & (CAND_OFFICE == "H" | CAND_OFFICE == "S") & (CAND_PTY_AFFILIATION == "REP" | CAND_PTY_AFFILIATION == "DEM")) %>%
select(CAND_ID, CAND_NAME, CAND_PTY_AFFILIATION, CAND_ELECTION_YR, CAND_OFFICE, CAND_OFFICE_ST, CAND_OFFICE_DISTRICT, CAND_PCC)
head(cn_14)
write.csv(cn_14, "output data/FEC Candidates/cn_14.csv")
# candidates 2016
cn_16 <- read.table("input data/FEC/Candidates/cn16.txt", header=FALSE, sep = '|', fill = TRUE, quote = "", col.names = cn_header[,1]) %>%
filter(CAND_ELECTION_YR == 2016 & (CAND_OFFICE == "H" | CAND_OFFICE == "S") & (CAND_PTY_AFFILIATION == "REP" | CAND_PTY_AFFILIATION == "DEM")) %>%
select(CAND_ID, CAND_NAME, CAND_PTY_AFFILIATION, CAND_ELECTION_YR, CAND_OFFICE, CAND_OFFICE_ST, CAND_OFFICE_DISTRICT, CAND_PCC)
head(cn_16)
write.csv(cn_16, "output data/FEC Candidates/cn_16.csv")
# candidates 2018
cn_18 <- read.table("input data/FEC/Candidates/cn18.txt", header=FALSE, sep = '|', fill = TRUE, quote = "", col.names = cn_header[,1]) %>%
filter(CAND_ELECTION_YR == 2018 & (CAND_OFFICE == "H" | CAND_OFFICE == "S") & (CAND_PTY_AFFILIATION == "REP" | CAND_PTY_AFFILIATION == "DEM")) %>%
select(CAND_ID, CAND_NAME, CAND_PTY_AFFILIATION, CAND_ELECTION_YR, CAND_OFFICE, CAND_OFFICE_ST, CAND_OFFICE_DISTRICT, CAND_PCC)
head(cn_18)
write.csv(cn_18, "output data/FEC Candidates/cn_18.csv")
# candidates 2020
cn_20 <- read.table("input data/FEC/Candidates/cn20.txt", header=FALSE, sep = '|', fill = TRUE, quote = "", col.names = cn_header[,1]) %>%
filter(CAND_ELECTION_YR == 2020 & (CAND_OFFICE == "H" | CAND_OFFICE == "S") & (CAND_PTY_AFFILIATION == "REP" | CAND_PTY_AFFILIATION == "DEM")) %>%
select(CAND_ID, CAND_NAME, CAND_PTY_AFFILIATION, CAND_ELECTION_YR, CAND_OFFICE, CAND_OFFICE_ST, CAND_OFFICE_DISTRICT, CAND_PCC)
head(cn_20)
write.csv(cn_20, "output data/FEC Candidates/cn_20.csv")
# candidates 2022
cn_22 <- read.table("input data/FEC/Candidates/cn22.txt", header=FALSE, sep = '|', fill = TRUE, quote = "", col.names = cn_header[,1]) %>%
filter(CAND_ELECTION_YR == 2022 & (CAND_OFFICE == "H" | CAND_OFFICE == "S") & (CAND_PTY_AFFILIATION == "REP" | CAND_PTY_AFFILIATION == "DEM")) %>%
select(CAND_ID, CAND_NAME, CAND_PTY_AFFILIATION, CAND_ELECTION_YR, CAND_OFFICE, CAND_OFFICE_ST, CAND_OFFICE_DISTRICT, CAND_PCC)
head(cn_22)
write.csv(cn_22, "output data/FEC Candidates/cn_22.csv")
```
FEC Candidate-Committee Linkage
```{r}
# candidate-committee linkage header
ccl_header <- t((fread("input data/FEC/Candidate-Committee Linkage/ccl_header_file.csv", header=FALSE)))
# candidate-committee linkage 2012
ccl_12 <- read.table("input data/FEC/Candidate-Committee Linkage/ccl12.txt", header=FALSE, sep = '|', fill = TRUE, quote = "", col.names = ccl_header[,1]) %>% filter(CAND_ELECTION_YR == 2012) %>%
select(CAND_ID, CAND_ELECTION_YR, CMTE_ID, LINKAGE_ID)
head(ccl_12)
write.csv(ccl_12, "output data/FEC Candidate-Committee/ccl_12.csv")
# candidate-committee linkage 2014
ccl_14 <- read.table("input data/FEC/Candidate-Committee Linkage/ccl14.txt", header=FALSE, sep = '|', fill = TRUE, quote = "", col.names = ccl_header[,1]) %>%
filter(CAND_ELECTION_YR == 2014) %>%
select(CAND_ID, CAND_ELECTION_YR, CMTE_ID, LINKAGE_ID)
head(ccl_14)
write.csv(ccl_14, "output data/FEC Candidate-Committee/ccl_14.csv")
# candidate-committee linkage 2016
ccl_16 <- read.table("input data/FEC/Candidate-Committee Linkage/ccl16.txt", header=FALSE, sep = '|', fill = TRUE, quote = "", col.names = ccl_header[,1]) %>%
filter(CAND_ELECTION_YR == 2016) %>%
select(CAND_ID, CAND_ELECTION_YR, CMTE_ID, LINKAGE_ID)
head(ccl_16)
write.csv(ccl_16, "output data/FEC Candidate-Committee/ccl_16.csv")
# candidate-committee linkage 2018
ccl_18 <- read.table("input data/FEC/Candidate-Committee Linkage/ccl18.txt", header=FALSE, sep = '|', fill = TRUE, quote = "", col.names = ccl_header[,1]) %>%
filter(CAND_ELECTION_YR == 2018) %>%
select(CAND_ID, CAND_ELECTION_YR, CMTE_ID, LINKAGE_ID)
head(ccl_18)
write.csv(ccl_18, "output data/FEC Candidate-Committee/ccl_18.csv")
# candidate-committee linkage 2020
ccl_20 <- read.table("input data/FEC/Candidate-Committee Linkage/ccl20.txt", header=FALSE, sep = '|', fill = TRUE, quote = "", col.names = ccl_header[,1]) %>%
filter(CAND_ELECTION_YR == 2020) %>%
select(CAND_ID, CAND_ELECTION_YR, CMTE_ID, LINKAGE_ID)
head(ccl_20)
write.csv(ccl_20, "output data/FEC Candidate-Committee/ccl_20.csv")
# candidate-committee linkage 2022
ccl_22 <- read.table("input data/FEC/Candidate-Committee Linkage/ccl22.txt", header=FALSE, sep = '|', fill = TRUE, quote = "", col.names = ccl_header[,1]) %>%
filter(CAND_ELECTION_YR == 2022) %>%
select(CAND_ID, CAND_ELECTION_YR, CMTE_ID, LINKAGE_ID)
head(ccl_22)
write.csv(ccl_22, "output data/FEC Candidate-Committee/ccl_22.csv")
```
Join FEC Data
```{r}
# 2012 fec data
fec_12 <- ind_12 %>%
inner_join(ccl_12, by = c("CMTE_ID")) %>%
inner_join(cn_12, by = c("CAND_ID"))
head(fec_12)
write.csv(fec_12, "output data/FEC Joined/fec_12.csv")
# 2014 fec data
fec_14 <- ind_14 %>%
inner_join(ccl_14, by = c("CMTE_ID")) %>%
inner_join(cn_14, by = c("CAND_ID"))
head(fec_14)
write.csv(fec_14, "output data/FEC Joined/fec_14.csv")
# 2016 fec data
fec_16 <- ind_16 %>%
inner_join(ccl_16, by = c("CMTE_ID")) %>%
inner_join(cn_16, by = c("CAND_ID"))
head(fec_16)
write.csv(fec_16, "output data/FEC Joined/fec_16.csv")
# 2018 fec data
fec_18 <- ind_18 %>%
inner_join(ccl_18, by = c("CMTE_ID")) %>%
inner_join(cn_18, by = c("CAND_ID"))
head(fec_18)
write.csv(fec_18, "output data/FEC Joined/fec_18.csv")
# 2020 fec data
fec_20 <- ind_20 %>%
inner_join(ccl_20, by = c("CMTE_ID")) %>%
inner_join(cn_20, by = c("CAND_ID"))
head(fec_20)
write.csv(fec_20, "output data/FEC Joined/fec_20.csv")
# 2022 fec data
fec_22 <- ind_22 %>%
inner_join(ccl_22, by = c("CMTE_ID")) %>%
inner_join(cn_22, by = c("CAND_ID"))
head(fec_22)
write.csv(fec_22, "output data/FEC Joined/fec_22.csv")
```