diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index ed7650c..e59feb3 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -2,9 +2,9 @@ # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help on: push: - branches: [main, master] + branches: [main] pull_request: - branches: [main, master] + branches: [main, dev] release: types: [published] workflow_dispatch: diff --git a/.gitignore b/.gitignore index b01934e..1f75b5c 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,5 @@ docs/ vignettes/synth_cache + +KPEcd2008.csv diff --git a/DESCRIPTION b/DESCRIPTION index 179aaf1..697f445 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -26,7 +26,6 @@ Imports: magrittr, fs, rlang, - Formula, dplyr (>= 1.1.0), tidyr, haven (>= 2.1.0), diff --git a/NEWS.md b/NEWS.md index d27a7fb..da042fc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,8 @@ # cccesMRPprep 0.1.13 * Add 2022, 2024, 2006, and 2012 daily kos cd data +* Fix minor error where pct values in cd_info from 2006-2012, 2022-2024 were not using two-party voteshare +* cd_info now distinguishes between total votes including third party (`presvotes_total`) and D+R votes (`presvotes_DR`) # cccesMRPprep 0.1.12 diff --git a/R/cces_std-for-acs.R b/R/cces_std-for-acs.R index d3820cd..0c08ee6 100644 --- a/R/cces_std-for-acs.R +++ b/R/cces_std-for-acs.R @@ -146,12 +146,12 @@ ccc_std_demographics <- function(tbl, # hispanic conversion if (wh_as_hisp && ("hispanic" %in% colnames(tbl_mod))) { tbl_mod <- tbl_mod %>% - mutate(race = replace(race, race_cces_chr == "White" & hispanic == 1, race_cces_to_acs$race[3])) + mutate(race = replace(race, race_cces_chr == "White" & .data$hispanic == 1, race_cces_to_acs$race[3])) } if (bh_as_hisp && ("hispanic" %in% colnames(tbl_mod))) { tbl_mod <- tbl_mod %>% - mutate(race = replace(race, race_cces_chr == "Black" & hispanic == 1, race_cces_to_acs$race[3])) + mutate(race = replace(race, race_cces_chr == "Black" & .data$hispanic == 1, race_cces_to_acs$race[3])) } if ((!is.null(wh_as_hisp) | !is.null(bh_as_hisp)) & @@ -164,7 +164,7 @@ ccc_std_demographics <- function(tbl, matches("weight"), matches("(state|st|cd|dist)"), matches("gender"), - female, + matches("^female$"), matches("pid3$"), matches("age"), matches("educ"), diff --git a/R/datadoc_cd-info-long.R b/R/datadoc_cd-info-long.R index 587baea..079902c 100644 --- a/R/datadoc_cd-info-long.R +++ b/R/datadoc_cd-info-long.R @@ -16,8 +16,9 @@ #' \item{`party`, `candidate`}{Define the presidential candidate that corresponds to the `elec` #' (which may not be the same as `lines`). For example, `lines = 2012, cd = AL-01` combined with #' `elec = 2008` represents the 2008 election results in the newly redistricted (2012) AL-01 geography} -#' \item{`pct`}{are the two party voteshares of the candidate} -#' \item{`presvotes_total`}{Is the total number of votes for President in that CD} +#' \item{`pct`}{The two party voteshares of the candidate} +#' \item{`presvotes_total`}{The total number of votes for President in that CD} +#' \item{`presvotes_DR`}{The total number of Democrat + Republican votes for President in that CD} #' } #' #' @examples diff --git a/R/datadoc_cd-info.R b/R/datadoc_cd-info.R index 9459c67..87bbbe9 100644 --- a/R/datadoc_cd-info.R +++ b/R/datadoc_cd-info.R @@ -5,6 +5,7 @@ #' district-level. We include one such data for congressional districts. All data #' is collected by The Downballot. #' +#' @name cd_info #' @details `cd_info_2008` is data on boundaries used in 2006, 2008, and 2010; #' `cd_info_2012` is data on boundaries used in 2012 and 2014; `cd_info_2016` #' uses 2016 boundaries; `cd_info_2018` is data on 2018 boundaries; @@ -28,17 +29,19 @@ #' @format Each `cd_info_20**` is a dataframe with the `r nrow(cd_info_2018)` Congressional #' Districts, one row per cd. #' \describe{ -#' \item{`year`}{The year for the district line. A congressional district's -#' actual geography can change year to year, and significantly so in different -#' redistricting cycles. Lines try to get the contemporaneous district map, -#' so that cd_info_2016 uses 2016 maps and cd_info_2020 uses 2020 maps. -#' However, this work relies on the hard work of assembling precinct results by Daily Kos.} +#' \item{`year`}{The year for the district map. A congressional district's +#' actual geography can change year to year. Lines represent the contemporaneous +#' district geography, +#' so that `cd_info_2016` uses 2016 maps and `cd_info_2020` uses 2020 maps. +#' Corresponds to `line` in `cd_info_long`. +#' This work relies on the hard work of assembling precinct results by Daily Kos.} #' \item{`cd`}{District code. The formatting corresponds to the CCES cumulative #' coding of \code{cd}: a two-letter abbreviation for the state followed by #' a dash, and the district number padded with zeros to the left to be of length #' 2. At-large districts like Delaware are given a "-01" for the district number. See `to_cd()`} #' \item{`presvotes_total`}{In presidential years, the total number of votes cast for -#' the office of President that year. Taken from Daily Kos estimates from precinct results.} +#' the office of President that year. } +#' \item{`presvotes_DR`}{Same as `presvotes_total` but only the sum of Democratic and Republican candidate's votes} #' \item{`pct_trump`, `pct_romney`, `pct_mccain`}{The two-party voteshare of Republican #' presidential candidates in that district for the given year. E.g. the #' \code{pct_mccain} data for `cd_info_2018` represents the percent @@ -53,7 +56,7 @@ #' have the same largest place.} #' } #' -#' @seealso cd_info_long +#' @seealso `cd_info_long` #' #' @source #' The Downballot (formerly Daily Kos Elections), \url{https://www.the-downballot.com/p/data} @@ -64,6 +67,9 @@ #' Daily Kos, "2008 results for districts used in **2006, 2008, 2010**" #' \url{https://bit.ly/4entUrV} #' +#' Kiernan Park-Egan, "U.S. Presidential Election Results by Congressional District, 1952 to 2020" +#' \url{https://bit.ly/4fk6UKx} (used for 2008 values only when Daily Kos has missing data) +#' #' Daily Kos, "2008, 2012 results for districts used in **2012, 2014**" #' \url{https://bit.ly/3N4PDZK} #' @@ -83,40 +89,44 @@ #' #' Pennsylvania 2016 CD names are named by Shiro Kuriwaki and Lara Putnam. #' -#' Also see Cha, Kuriwaki, and Snyder, 2021, -#' "Candidates in American General Elections", https://doi.org/10.7910/DVN/DGDRDT, -#' Harvard Dataverse. +#' Also see Cha, Kuriwaki, and Snyder, 2024, +#' "Candidates in American General Elections", \url{https://doi.org/10.7910/DVN/DGDRDT}, +#' Harvard Dataverse, for congressional candidate's (instead of President's) vote totals. #' #' #' @examples #' head(cd_info_2018) #' head(elec_NY) -"cd_info_2018" +NULL -#' @rdname cd_info_2018 +#' @rdname cd_info #' @format NULL "cd_info_2008" -#' @rdname cd_info_2018 +#' @rdname cd_info #' @format NULL "cd_info_2012" -#' @rdname cd_info_2018 +#' @rdname cd_info #' @format NULL "cd_info_2016" -#' @rdname cd_info_2018 +#' @rdname cd_info +#' @format NULL +"cd_info_2018" + +#' @rdname cd_info #' @format NULL "cd_info_2020" -#' @rdname cd_info_2018 +#' @rdname cd_info #' @format NULL "cd_info_2022" -#' @rdname cd_info_2018 +#' @rdname cd_info #' @format NULL "cd_info_2024" -#' @rdname cd_info_2018 +#' @rdname cd_info #' @format NULL "elec_NY" diff --git a/R/district-coding.R b/R/district-coding.R index e10af40..124490d 100644 --- a/R/district-coding.R +++ b/R/district-coding.R @@ -4,7 +4,7 @@ #'@param state A vector of state names, preferably abbreviations. #' If it is numeric, the function will assume they are FIPS codes #' and translate them accordingly. If they have full names like "California" -#' instead of "CA", it will trnslate that too. +#' instead of "CA", it will translate that too. But you cannot mix different types. #'@param num A vector of district codes #' #'@importFrom stringr str_pad @@ -29,12 +29,12 @@ to_cd <- function(state, num) { # State if (inherits(state, "haven_labelled") | is.numeric(state)) { - fips_to_st <- deframe(select(states_key, st_fips, st)) + fips_to_st <- deframe(select(states_key, .data$st_fips, .data$st)) state <- recode(as.numeric(state), !!!fips_to_st) } - if (all(state %in% c(states_key$state))) { - state_to_st <- deframe(select(states_key, state, st)) + if (all(state %in% c(ccesMRPprep::states_key$state))) { + state_to_st <- deframe(select(states_key, .data$state, .data$st)) state <- recode(state, !!!state_to_st) } diff --git a/README.Rmd b/README.Rmd index 68fe580..373c8ca 100644 --- a/README.Rmd +++ b/README.Rmd @@ -54,14 +54,13 @@ See the overview vignette (`vignette("overview")`) from a illustrative workflow. ## Data Sources -Function-specific pages will detail the documentation used in each function. Here is a manual compilaiton: +Function-specific pages will detail the documentation used in each function. Here is a manual compilation: | Information | Source | Citation and URL (if public) | | :--- | :--- | :--- | | CCES Covariates | Cumulative CCES | Shiro Kuriwaki, "Cumulative CCES Common Content". https://doi.org/10.7910/DVN/II2DB6 | | CCES Outcomes | Each Year's CCES | Stephen Ansolabehere, Sam Luks, and Brian Schaffner. "CCES Common Content" (varies by year). https://cces.gov.harvard.edu/ | | Poststratification | Census Bureau ACS | American Community Survey. Extracted via [tidycensus package](https://github.com/walkerke/tidycensus). See [ACS vignette](https://www.shirokuriwaki.com/ccesMRPprep/articles/acs.html) | -| District-level Contestedness and Incumbency | Collected mainly by Jim Snyder | | | CD-level Presidential Voteshare | Daily Kos | Daily Kos, [The ultimate Daily Kos Elections guide to all of our data sets](https://www.dailykos.com/stories/2018/2/21/1742660/-The-ultimate-Daily-Kos-Elections-guide-to-all-of-our-data-sets#1) | | State-level Presidential Voteshare | MEDSL | MIT Election Data and Science Lab, 2017, "U.S. President 1976–2016". https://doi.org/10.7910/DVN/42MVDX | @@ -71,7 +70,6 @@ Function-specific pages will detail the documentation used in each function. Her - [kuriwaki/rcces](https://github.com/kuriwaki/rcces) has another set of CCES related functions, but these are either my own personal functions in development (not for production), or specific to non-MRP projects. -- [kuriwaki/CCES_district-opinion](https://github.com/kuriwaki/CCES_district-opinion) is a private package that uses (among others) this package to process large CCES data for MRP at scale. ## Support diff --git a/README.md b/README.md index 14a9844..8852773 100644 --- a/README.md +++ b/README.md @@ -82,25 +82,21 @@ workflow. ## Data Sources Function-specific pages will detail the documentation used in each -function. Here is a manual compilaiton: +function. Here is a manual compilation: -| Information | Source | Citation and URL (if public) | -|:--------------------------------------------|:-------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| CCES Covariates | Cumulative CCES | Shiro Kuriwaki, “Cumulative CCES Common Content”. | -| CCES Outcomes | Each Year’s CCES | Stephen Ansolabehere, Sam Luks, and Brian Schaffner. “CCES Common Content” (varies by year). | -| Poststratification | Census Bureau ACS | American Community Survey. Extracted via [tidycensus package](https://github.com/walkerke/tidycensus). See [ACS vignette](https://www.shirokuriwaki.com/ccesMRPprep/articles/acs.html) | -| District-level Contestedness and Incumbency | Collected mainly by Jim Snyder | | -| CD-level Presidential Voteshare | Daily Kos | Daily Kos, [The ultimate Daily Kos Elections guide to all of our data sets](https://www.dailykos.com/stories/2018/2/21/1742660/-The-ultimate-Daily-Kos-Elections-guide-to-all-of-our-data-sets#1) | -| State-level Presidential Voteshare | MEDSL | MIT Election Data and Science Lab, 2017, “U.S. President 1976–2016”. | +| Information | Source | Citation and URL (if public) | +|:-----------------------------------|:------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| CCES Covariates | Cumulative CCES | Shiro Kuriwaki, “Cumulative CCES Common Content”. | +| CCES Outcomes | Each Year’s CCES | Stephen Ansolabehere, Sam Luks, and Brian Schaffner. “CCES Common Content” (varies by year). | +| Poststratification | Census Bureau ACS | American Community Survey. Extracted via [tidycensus package](https://github.com/walkerke/tidycensus). See [ACS vignette](https://www.shirokuriwaki.com/ccesMRPprep/articles/acs.html) | +| CD-level Presidential Voteshare | Daily Kos | Daily Kos, [The ultimate Daily Kos Elections guide to all of our data sets](https://www.dailykos.com/stories/2018/2/21/1742660/-The-ultimate-Daily-Kos-Elections-guide-to-all-of-our-data-sets#1) | +| State-level Presidential Voteshare | MEDSL | MIT Election Data and Science Lab, 2017, “U.S. President 1976–2016”. | ## Related Packages - [kuriwaki/rcces](https://github.com/kuriwaki/rcces) has another set of CCES related functions, but these are either my own personal functions in development (not for production), or specific to non-MRP projects. -- [kuriwaki/CCES_district-opinion](https://github.com/kuriwaki/CCES_district-opinion) - is a private package that uses (among others) this package to process - large CCES data for MRP at scale. ## Support diff --git a/_pkgdown.yml b/_pkgdown.yml index 2ea8fbc..a3e6e32 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -30,7 +30,7 @@ reference: - ccc_samp - cc18_samp - cc18_NY - - cd_info_2018 + - cd_info - cd_info_long - elec_NY - questions_samp diff --git a/data-raw/create_cd-info-long.R b/data-raw/create_cd-info-long.R index 969fb51..7e630b4 100644 --- a/data-raw/create_cd-info-long.R +++ b/data-raw/create_cd-info-long.R @@ -79,22 +79,25 @@ D_pct <- R_pct |> # same for Ns Ns <- cd_info_all |> - select(lines = year, cd, matches("total")) |> + select(lines = year, cd, matches("presvotes_")) |> pivot_longer( - matches("presvotes_total"), + matches("presvotes_"), names_prefix = "presvotes_", - values_to = "presvotes_total", values_drop_na = TRUE) |> + values_drop_na = TRUE) |> mutate(elec = case_when( - name == "total20" ~ 2020, - lines %in% c(2008, 2012, 2016, 2020) ~ lines, - lines == 2010 ~ 2008, - lines == 2014 ~ 2012, - lines == 2018 ~ 2016, - lines == 2022 ~ 2020, + name %in% c("total_20", "DR_20") ~ 2020, + name %in% c("total_16", "DR_16") ~ 2016, + name %in% c("total", "DR") & lines %in% c(2008, 2010) ~ 2008, + name %in% c("total", "DR") & lines %in% c(2012, 2014) ~ 2012, + name %in% c("total", "DR") & lines == 2022 ~ 2020, ), .after = cd ) |> - select(-name) + mutate(name = str_remove(name, "_.*")) |> + pivot_wider(id_cols = c(elec, lines, cd), + names_from = name, + values_from = value, + names_prefix = "presvotes_") cd_info_long <- bind_rows(D_pct, R_pct) |> tidylog::left_join(Ns, by = c("lines", "cd", "elec")) |> diff --git a/data-raw/create_dist-level-data_2006_2012.R b/data-raw/create_dist-level-data_2006_2012.R index a3ec5d1..4785fcb 100644 --- a/data-raw/create_dist-level-data_2006_2012.R +++ b/data-raw/create_dist-level-data_2006_2012.R @@ -11,40 +11,44 @@ url_2012 <- "https://docs.google.com/spreadsheets/d/1xn6nCNM97oFDZ4M-HQgoUT3X4pa # Read data from Google Sheets # 2008 -cd_names_2008 <- read_sheet(url_2008, range = "A2:E", col_names = TRUE, sheet = 1) |> +cd_names_2008 <- read_sheet(url_2008, range = "A2:A", col_names = TRUE, sheet = 1) |> mutate(year = 2008) |> select(year, - cd = CD, - mccain = McCain) + cd = CD) + +# https://yalemaps.maps.arcgis.com/home/item.html?id=35e8e9aa89b34a3a8a036b1be7ad6607 +voting_info_2008 <- read_csv("data-raw/KPEcd2008.csv") |> + filter(STATENAME != "District Of Columbia") |> + transmute(cd = to_cd(STATENAME, DISTRICT), + pct_mccain = GOP_VOT / (GOP_VOT + DEM_VOT), + presvotes_DR = GOP_VOT + DEM_VOT, + presvotes_total = TOT_VOT) -voting_info_2008 <- read_sheet(url_2008,range = "A2:I", col_names = TRUE, sheet = 2) |> - select(cd = CD, - # pct_mccain = 'McCain%', # replaced by McCain sheet one - presvotes_total = "Total") # 2012 cd_names_2012 <- read_sheet(url_2012, range = "A2:G", col_names = TRUE, sheet = 1) |> mutate(year = 2012) |> select(year, cd = CD) +# 2008 CA missing voting_info_2012 <- read_sheet(url_2012, range = "A2:O", col_names = TRUE, sheet = 2) |> - select(cd = CD, - presvotes_total = 7, - pct_romney = 'Romney%', - pct_mccain = 'McCain%') + transmute( + cd = CD, + pct_romney = Romney / (`Obama...5` + Romney), + presvotes_DR = `Obama...5` + Romney, + presvotes_total = `Total...7`) # Join data from page 1 and page 2 for each dataset cd_info_2008 <- cd_names_2008 |> - left_join(voting_info_2008, by = "cd") |> mutate(cd = str_replace(cd, "-AL$", "-01")) |> - mutate(pct_mccain = mccain * 0.01) |> - select(!mccain) |> - relocate(year, cd, pct_mccain, presvotes_total) + left_join(voting_info_2008, by = "cd") |> + relocate(year, cd, pct_mccain) cd_info_2012 <- cd_names_2012 |> left_join(voting_info_2012, by = "cd") |> mutate(cd = str_replace(cd, "-AL$", "-01")) + # Save the data usethis::use_data(cd_info_2012, overwrite = TRUE) usethis::use_data(cd_info_2008, overwrite = TRUE) diff --git a/data-raw/create_dist-level-data.R b/data-raw/create_dist-level-data_2016-2020.R similarity index 71% rename from data-raw/create_dist-level-data.R rename to data-raw/create_dist-level-data_2016-2020.R index 34da955..d2e0064 100644 --- a/data-raw/create_dist-level-data.R +++ b/data-raw/create_dist-level-data_2016-2020.R @@ -7,31 +7,32 @@ library(fs) projdir <- "~/Dropbox/CCES_representation/data/output/" - +url_2018 <- "https://docs.google.com/spreadsheets/d/1zLNAuRqPauss00HDz4XbTH2HqsCzMe0pR8QmD1K8jk8" cd_info_2020 <- read_rds(path(projdir, "averages/by-cd-2020_info.Rds")) %>% mutate(year = 2020) %>% select(year, cd, dailykos_name = descrip_18, largest_place = place_18, - presvotes_total = pres_all_total, - pct_trump, pct_trump16, pct_romney) + pct_trump, pct_trump16, pct_romney, + matches("presvotes")) +# 2018 ---- cd_info_2018 <- read_rds(path(projdir, "averages/by-cd-2018_info.Rds")) %>% mutate(year = 2018) %>% select(year, cd, dailykos_name = descrip, largest_place = place, - pct_trump, pct_romney, pct_mccain) - - + pct_trump, pct_romney, pct_mccain, + matches("presvotes")) +# 2016 --- cd_info_2016 <- read_rds(path(projdir, "averages/by-cd-2016_info.Rds")) %>% mutate(year = 2016) %>% select(year, cd, dailykos_name = descrip_16, - presvotes_total = pres_all_total, - pct_trump, pct_romney, pct_mccain) + pct_trump, pct_romney, pct_mccain, + matches("presvotes")) usethis::use_data(cd_info_2016, overwrite = TRUE) diff --git a/data-raw/create_dist-level-data_2022-2024.R b/data-raw/create_dist-level-data_2022-2024.R index ba67d7f..a79e0c1 100644 --- a/data-raw/create_dist-level-data_2022-2024.R +++ b/data-raw/create_dist-level-data_2022-2024.R @@ -18,10 +18,11 @@ cd_names_2022 <- read_sheet(url_2022, sheet = 1) |> select(year, cd = District) voting_info_2022 <- read_sheet(url_2022, sheet = 2) |> - select(cd = District, - pct_trump = 'Trump %', - presvotes_total = Total - ) + transmute(cd = District, + pct_trump = Trump / (Biden + Trump), + presvotes_DR = Biden + Trump, + presvotes_total = Total + ) region_2022 <- read_sheet(url_geo_118, sheet = 1) |> select(cd = CD, @@ -37,9 +38,10 @@ cd_names_2024 <- read_sheet(url_2024, sheet = 1) |> select(year, cd = District) voting_info_2024 <- read_sheet(url_2024, sheet = 2) |> - select(cd = District, - pct_trump20 = 'Trump %', - presvotes_total20 = Total) + transmute(cd = District, + pct_trump20 = Trump / (Biden + Trump), + presvotes_DR_20 = Biden + Trump, + presvotes_total_20 = Total) region_2024 <- read_sheet(url_geo_119, sheet = 1) |> select(cd = CD, diff --git a/data/cd_info_2008.rda b/data/cd_info_2008.rda index b66785d..62e7043 100644 Binary files a/data/cd_info_2008.rda and b/data/cd_info_2008.rda differ diff --git a/data/cd_info_2012.rda b/data/cd_info_2012.rda index c6560a6..1ed7f5d 100644 Binary files a/data/cd_info_2012.rda and b/data/cd_info_2012.rda differ diff --git a/data/cd_info_2016.rda b/data/cd_info_2016.rda index 3ffb814..a11953c 100644 Binary files a/data/cd_info_2016.rda and b/data/cd_info_2016.rda differ diff --git a/data/cd_info_2018.rda b/data/cd_info_2018.rda index 8cf86f3..fb63788 100644 Binary files a/data/cd_info_2018.rda and b/data/cd_info_2018.rda differ diff --git a/data/cd_info_2020.rda b/data/cd_info_2020.rda index 2861f58..0eb6f5b 100644 Binary files a/data/cd_info_2020.rda and b/data/cd_info_2020.rda differ diff --git a/data/cd_info_2022.rda b/data/cd_info_2022.rda index b403c29..35f640e 100644 Binary files a/data/cd_info_2022.rda and b/data/cd_info_2022.rda differ diff --git a/data/cd_info_2024.rda b/data/cd_info_2024.rda index 96d9d6d..7b0762b 100644 Binary files a/data/cd_info_2024.rda and b/data/cd_info_2024.rda differ diff --git a/data/cd_info_long.rda b/data/cd_info_long.rda index 665ec3e..eec39d4 100644 Binary files a/data/cd_info_long.rda and b/data/cd_info_long.rda differ diff --git a/man/cd_info_2018.Rd b/man/cd_info.Rd similarity index 82% rename from man/cd_info_2018.Rd rename to man/cd_info.Rd index bf504f6..a42828c 100644 --- a/man/cd_info_2018.Rd +++ b/man/cd_info.Rd @@ -1,11 +1,12 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/datadoc_cd-info.R \docType{data} -\name{cd_info_2018} -\alias{cd_info_2018} +\name{cd_info} +\alias{cd_info} \alias{cd_info_2008} \alias{cd_info_2012} \alias{cd_info_2016} +\alias{cd_info_2018} \alias{cd_info_2020} \alias{cd_info_2022} \alias{cd_info_2024} @@ -15,17 +16,19 @@ Each \verb{cd_info_20**} is a dataframe with the 435 Congressional Districts, one row per cd. \describe{ -\item{\code{year}}{The year for the district line. A congressional district's -actual geography can change year to year, and significantly so in different -redistricting cycles. Lines try to get the contemporaneous district map, -so that cd_info_2016 uses 2016 maps and cd_info_2020 uses 2020 maps. -However, this work relies on the hard work of assembling precinct results by Daily Kos.} +\item{\code{year}}{The year for the district map. A congressional district's +actual geography can change year to year. Lines represent the contemporaneous +district geography, +so that \code{cd_info_2016} uses 2016 maps and \code{cd_info_2020} uses 2020 maps. +Corresponds to \code{line} in \code{cd_info_long}. +This work relies on the hard work of assembling precinct results by Daily Kos.} \item{\code{cd}}{District code. The formatting corresponds to the CCES cumulative coding of \code{cd}: a two-letter abbreviation for the state followed by a dash, and the district number padded with zeros to the left to be of length 2. At-large districts like Delaware are given a "-01" for the district number. See \code{to_cd()}} \item{\code{presvotes_total}}{In presidential years, the total number of votes cast for -the office of President that year. Taken from Daily Kos estimates from precinct results.} +the office of President that year. } +\item{\code{presvotes_DR}}{Same as \code{presvotes_total} but only the sum of Democratic and Republican candidate's votes} \item{\code{pct_trump}, \code{pct_romney}, \code{pct_mccain}}{The two-party voteshare of Republican presidential candidates in that district for the given year. E.g. the \code{pct_mccain} data for \code{cd_info_2018} represents the percent @@ -49,6 +52,9 @@ The Daily Kos Elections naming guide to the nation's congressional districts. Daily Kos, "2008 results for districts used in \strong{2006, 2008, 2010}" \url{https://bit.ly/4entUrV} +Kiernan Park-Egan, "U.S. Presidential Election Results by Congressional District, 1952 to 2020" +\url{https://bit.ly/4fk6UKx} (used for 2008 values only when Daily Kos has missing data) + Daily Kos, "2008, 2012 results for districts used in \strong{2012, 2014}" \url{https://bit.ly/3N4PDZK} @@ -70,19 +76,19 @@ Daily Kos, congressional district geography and most populous places: Pennsylvania 2016 CD names are named by Shiro Kuriwaki and Lara Putnam. -Also see Cha, Kuriwaki, and Snyder, 2021, -"Candidates in American General Elections", https://doi.org/10.7910/DVN/DGDRDT, -Harvard Dataverse. +Also see Cha, Kuriwaki, and Snyder, 2024, +"Candidates in American General Elections", \url{https://doi.org/10.7910/DVN/DGDRDT}, +Harvard Dataverse, for congressional candidate's (instead of President's) vote totals. } \usage{ -cd_info_2018 - cd_info_2008 cd_info_2012 cd_info_2016 +cd_info_2018 + cd_info_2020 cd_info_2022 @@ -123,6 +129,6 @@ head(cd_info_2018) head(elec_NY) } \seealso{ -cd_info_long +\code{cd_info_long} } \keyword{datasets} diff --git a/man/cd_info_long.Rd b/man/cd_info_long.Rd index 119da19..ff793df 100644 --- a/man/cd_info_long.Rd +++ b/man/cd_info_long.Rd @@ -5,7 +5,7 @@ \alias{cd_info_long} \title{Congressional District level information - long version} \format{ -\code{cd_info_long} is a dataframe with 14578 rows, +\code{cd_info_long} is a dataframe with 13050 rows, covering the maps of 9 election years (2008, 2010, 2012, 2014, 2016, 2018, 2020, 2022, 2024) for each of the 435 congressional districts. \describe{ @@ -18,8 +18,9 @@ than the same first congressional district for another.} \item{\code{party}, \code{candidate}}{Define the presidential candidate that corresponds to the \code{elec} (which may not be the same as \code{lines}). For example, \verb{lines = 2012, cd = AL-01} combined with \code{elec = 2008} represents the 2008 election results in the newly redistricted (2012) AL-01 geography} -\item{\code{pct}}{are the two party voteshares of the candidate} -\item{\code{presvotes_total}}{Is the total number of votes for President in that CD} +\item{\code{pct}}{The two party voteshares of the candidate} +\item{\code{presvotes_total}}{The total number of votes for President in that CD} +\item{\code{presvotes_DR}}{The total number of Democrat + Republican votes for President in that CD} } } \usage{ diff --git a/man/to_cd.Rd b/man/to_cd.Rd index cecc458..c4582d3 100644 --- a/man/to_cd.Rd +++ b/man/to_cd.Rd @@ -10,7 +10,7 @@ to_cd(state, num) \item{state}{A vector of state names, preferably abbreviations. If it is numeric, the function will assume they are FIPS codes and translate them accordingly. If they have full names like "California" -instead of "CA", it will trnslate that too.} +instead of "CA", it will translate that too. But you cannot mix different types.} \item{num}{A vector of district codes} }