Skip to content

Commit 7384d96

Browse files
authored
add public voter participation data (#107)
1 parent 3cff603 commit 7384d96

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Voter Participation Rates
2+
3+
[![latest github release](https://img.shields.io/github/v/release/geomarker-io/codec?sort=date&filter=voter_participation-*&display_name=tag&label=%5B%E2%98%B0%5D&labelColor=%238CB4C3&color=%23396175)](https://github.com/geomarker-io/codec/releases?q=voter_participation&expanded=false)
4+
5+
Voter lists exported from https://votehamiltoncountyohio.gov are downloaded and converted into census-tract level voting participation rates for recent elections.
6+
7+
Versions are tagged based on the semantic version of the code and the date on which the data is based separated by a hypen (e.g., `0.1-20241104` is the 0.1 version of the code that downloaded the voter records on November 4th, 2024).
8+
9+
- Use https://votehamiltoncountyohio.gov/download.php?file=VoterListExport-20240905-no.csv pattern to download files; data will change depending on date of download, but script always uses the current date. (Note that historical voter records are not available using the VoterListExport URLs.)
10+
- Assume that each voter's address represents their most recently registered address and may not reflect their registered address during older elections.
11+
- Concatenate `AddressPreDirectional`, `AddressNumber`, `AddressStreet`, `AddressSuffix`, `CityName`, `"OH"` and `AddressZip` to create `voter_address`.
12+
- Use the "[voting history legend](https://votehamiltoncountyohio.gov/campaign-media/voter-lists/)" described in the data documentation to dichotomize the voting status for each voter in each election. Voters were considered to have participated if they voted (either in person on election day, absentee, or early at an Early Vote Center) regardless of declared party affiliation (i.e., a non-missing value equals voter participation).
13+
- Use the address matching and street range geocoding in the parcel pacakge to match each `voter_address` with a Hamilton County census tract.
14+
- Calculate census tract rates of voter participation as the number of registered voters who participated divided by the total number of registered voters.
15+
16+
More info: https://votehamiltoncountyohio.gov/campaign-media/voter-lists/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
if (tryCatch(read.dcf("DESCRIPTION")[1, "Package"] == "codec", finally = FALSE)) {
2+
devtools::load_all()
3+
} else {
4+
library(codec)
5+
}
6+
7+
library(dplyr, warn.conflicts = FALSE)
8+
library(readr, warn.conflicts = FALSE)
9+
library(addr)
10+
library(dpkg)
11+
12+
sessionInfo()
13+
14+
rd <- read_csv(
15+
glue::glue(
16+
"https://votehamiltoncountyohio.gov/download.php?file=VoterListExport-",
17+
format(Sys.Date(), "%Y%m%d"),
18+
"-no.csv"
19+
),
20+
col_types =
21+
cols_only(
22+
AddressPreDirectional = col_character(),
23+
AddressNumber = col_double(),
24+
AddressStreet = col_character(),
25+
AddressSuffix = col_character(),
26+
CityName = col_character(),
27+
AddressZip = col_character(),
28+
`2024 General Election` = col_factor(),
29+
`2024 Primary Election` = col_factor(),
30+
`2023 General Election` = col_factor(),
31+
`2023 August Election` = col_factor(),
32+
PRIMARY_MAY_2023 = col_factor(),
33+
GENERAL_NOV_2022 = col_factor(),
34+
`AUG PRIMARY ELECTION 2022` = col_factor(),
35+
PRIMARY_MAY_2022 = col_factor(),
36+
GENERAL_NOV_2021 = col_factor(),
37+
PRIMARY_MAY_2021 = col_factor(),
38+
GENERAL_NOV_2020 = col_factor(),
39+
SPECIAL_AUG_2020 = col_factor()
40+
)
41+
)
42+
43+
d <-
44+
rd |>
45+
mutate(foofy_state = "OH") |>
46+
tidyr::unite("voter_address",
47+
c(
48+
AddressPreDirectional, AddressNumber, AddressStreet,
49+
AddressSuffix, CityName, foofy_state, AddressZip
50+
),
51+
sep = " ",
52+
remove = TRUE,
53+
na.rm = TRUE
54+
)
55+
56+
cagis_s2 <-
57+
cagis_addr()$cagis_addr_data |>
58+
purrr::modify_if(\(.) length(.) > 0 && nrow(.) > 1, dplyr::slice_sample, n = 1) |>
59+
purrr::map_vec(purrr::pluck, "cagis_s2", .default = NA, .ptype = s2::s2_cell())
60+
61+
d_geocode <- addr::addr_match_geocode(
62+
x = d$voter_address,
63+
ref_addr = cagis_addr()$cagis_addr,
64+
ref_s2 = cagis_s2,
65+
county = "39061",
66+
year = "2022"
67+
)
68+
69+
d_geocode <- d_geocode |>
70+
mutate(
71+
bg = s2_join_tiger_bg(s2, "2023"),
72+
tract = substr(bg, 1, 11)
73+
)
74+
75+
d_rates <-
76+
bind_cols(d, d_geocode) |>
77+
group_by(tract) |>
78+
summarize(across(
79+
c(
80+
`2024 General Election`, `2024 Primary Election`,
81+
`2023 General Election`, `2023 August Election`,
82+
PRIMARY_MAY_2023, GENERAL_NOV_2022,
83+
`AUG PRIMARY ELECTION 2022`, PRIMARY_MAY_2022,
84+
GENERAL_NOV_2021, PRIMARY_MAY_2021,
85+
GENERAL_NOV_2020, SPECIAL_AUG_2020
86+
),
87+
\(.) sum(!is.na(.)) / length(.)
88+
))
89+
90+
out <-
91+
cincy::tract_tigris_2020 |>
92+
sf::st_drop_geometry() |>
93+
as_tibble() |>
94+
left_join(d_rates, by = c("census_tract_id_2020" = "tract"))
95+
96+
out_dpkg <-
97+
out |>
98+
mutate(year = "2024") |>
99+
as_codec_dpkg(
100+
name = "voter_participation",
101+
version = glue::glue("0.1-", format(Sys.Date(), "%Y%m%d")),
102+
title = "Voter Participation Rates",
103+
homepage = "https://geomarker.io/codec",
104+
description = paste(readLines(fs::path_package("codec", "codec_data", "voter_participation", "README.md")), collapse = "\n")
105+
)
106+
107+
dpkg::dpkg_gh_release(out_dpkg, draft = FALSE)

0 commit comments

Comments
 (0)