Measurement(s)Election resultsTechnology Type(s)Scripts for collection, cleaning, and quality assurance
We describe the creation and quality assurance of a dataset containing nearly all available precinct-level election results from the 2016, 2018, and 2020 American elections. Precincts are the smallest level of election administration, and election results at this granularity are needed to address many important questions. However, election results are individually reported by each state with little standardization or data quality assurance. We have collected, cleaned, and standardized precinct-level election results from every available race above the very local level in almost every state across the last three national election years. Our data include nearly every candidate for president, US Congress, governor, or state legislator, and hundreds of thousands of precinct-level results for judicial races, other statewide races, and even local races and ballot initiatives. In this article we describe the process of finding this information and standardizing it. Then we aggregate the precinct-level results up to geographies that have official totals, and show that our totals never differ from the official nationwide data by more than 0.457%.
Background & SummaryAmerican election results are widely available at the largest relevant geography: governments and news outlets publish statewide vote counts for presidential, gubernatorial, and US Senate elections, while races for the US House of Representatives and for state legislatures are commonly released at the electoral district level1,2. In contrast, each state can choose whether and how to publish election results at lower administrative levels, so it is much more difficult to acquire, standardize, and audit the accuracy of these data. The most granular election results that states share are vote counts in each precinct, which is a geographical unit close to the level of a single polling location, typically containing a few hundred or a few thousand voters. Since 2016, we have collected and standardized the precinct-level results of national general elections, producing datasets for the 2016, 2018, and 2020 contests. Together these datasets contain over 36,000,000 rows, most of which represent the vote totals for a unique candidate-precinct combination.Granular vote count data are required for many important questions. Local election results are widely used in quantitative political science3–5, and one classic application is the study of legislative districts and gerrymandering reform6–10. These data also have applications across many empirical sciences. Prominent applications of precinct- or county-level election results include modeling public health outcomes, particularly related to COVID-1911–16; local-level analyses of municipal spending, policing and crime reporting, the effectiveness of public communication, and the usage or regulation of land, water, and energy17–23; estimating neighbourhood-level demographics24; modeling small-scale labour markets or the effects of macro-economic events25,26; and even demonstrating how a new method in statistics or data science can be applied to important questions27,28.However, it can be extremely difficult to acquire usable precinct-level election results. There are nearly 180,000 precincts across the 50 states and the District of Columbia; in every election, many candidates compete for numerous public offices in each of these precincts. In a general election there can be on the order of ten million unique combinations of precincts and candidates. But American election administration is decentralized, with election results reported individually by each state. States and localities construct precincts in very different ways, and some states change their number and composition annually without any clear means of matching them29. States then release election data in inconsistent formats that require customized cleaning to merge into a standardized dataset, and these results frequently contain issues that must be identified and corrected, especially for any analysis that concerns geography or spans multiple elections.Perhaps the first effort to create national datasets of precinct-level election results was The Record of American Democracy30, followed by partisan efforts in the 2000s31. The Harvard Election Data Archive released precinct-level data for elections between 2002 and 2012, and OpenPrecincts and the Voting and Election Science Team have curated maps of precinct-level vote counts. The Redistricting Data Hub coordinated granular data collection efforts from many sources to help support public efforts to influence the post-2020 redistricting process in the United States32,33. Nevertheless, granular election data remain quite rare. Ours is the only effort since 2012 that has produced cleaned, standardized, quality assured, nearly complete, and freely available precinct-level election results for all states and for all offices for which the data are available. Ours is also the only precinct-level vote-count project that preserves information about the mode in which the votes were cast (in-person on Election Day, in-person before Election Day, and absentee), when available.Table 1 shows the number of precincts and candidates in our datasets, broken down by the major types of electoral contest: presidential, congressional, gubernatorial, state legislative, judicial, other statewide, local, and referenda. We believe that our data include nearly every vote-getting candidate above the municipal or county level, in nearly every precinct in the country, with just three states missing: Indiana in 2018 and 2020, and New York in 2018, which did not release sufficiently complete or accurate precinct-level results (we do include states, like New Jersey and Maine, which reported township-level data). In addition to major legislative races from tens or hundreds of thousands of precincts, these data also include at least some results for regional positions like county courts and railroad commissions; ballot questions and referenda; very local races like schoolboard trustees and town aldermen; and some meta-information like the number of registered voters or absentee ballot return rates. In this article we describe the process of acquiring, standardizing, and assuring the quality of these data. We also show that when our hyper-local data are aggregated up to the national level, they are extremely close to the official results.Table 1The extent of the data about different types of races.Race typePrecincts 2020Candidates 2020Precincts 2018Candidates 2018Precincts 2016Candidates 2016President176,618536——182,669801US Senate74,181192132,926385140,657223US House171,4761,830172,8741,487155,7871,356Governors/Lt. Governors12,923324139,10378122,88787State senates102,1805,47785,8392,96190,4922,146State houses166,59912,491155,6349,647128,8777,669Judicial races64,2872,15174,6395,29669,6721,727Other state-wide races48,0241,074120,5281,354141,72612,277Local races9,1681,129138,19527,16544,74815,627Ballot questions90,034—85,681—84,553—Meta-information77,953—75,818—5,618—The figures for President, US Senate, US House, governors, state senates, and state houses are precise counts. The other figures are not exact because they concern too many millions of rows, with thousands of unique custom descriptions of ballot questions or races at regional and local levels, but they are estimates based on a combination of string searches and manually classifying the descriptions of the race provided by each state. Large variations between years in some offices partly reflect real differences in how much information our data contains for each office across the different years, but are also partly attributable to data being reported in quite different ways in different years, with some states for example splitting the same amount of information into more precincts in one year than in another. States sometimes report ballots in aggregations that are not exactly geographic precincts, and we retain that information, so these figures are somewhat larger than the number of literal geographic precincts; for example, some counties report all of their absentee ballots as though they correspond to an “absentee ballot precinct”, and we retain that fictitious precinct alongside geographic precincts.MethodsData acquisition and completenessIn order to include a state’s election results in our datasets (from now on we will use “state” to mean “state or Washington, D.C.”), the first challenge is to find reported election results which include all of the following information: geographic data down to the precinct level (precinct, county, and state names, and standard numerical identifiers where applicable), the public office that the race is for (like the presidency or the US Senate), the candidate’s name, their political party, the mode by which the votes were cast (such as absentee or provisional ballots), the number of votes, and the stage of the election (such as whether this is a general election, a primary election, or a run-off). The 2016 data have several other types of identifiers for candidates and geographies. The variables that contain this information (36 variables in 2016, 25 variables in 2018 and 2020) are listed in Table 2.Table 2The variables in our datasets and their meanings.YearsNameMeaningallprecinctThe name of the precinctallcandidateThe name of a candidate who received votes in that precinctallvotesThe number of votes the candidate received in the precinctallofficeThe name of the public office to which the candidate is seeking election18/20party_detailedThe full name of the candidate’s political party18/20party_simplifiedJust the major parties, with others marked as “other”2016partyThe party name, not split into detailed and simplified in the 2016 dataallmodeThe type of vote cast, like “absentee” or “provisional”allwriteinWhether or not the votes are write-in votes18/20magnitudeHow many candidates people can vote for in that electionallstageThe part of the election, like whether it is a general or primary electionallspecialWhether or not the election is a special election18/20dateThe date of the electionallyearThe election yearalljurisdiction_nameName of the next local government up (township or county)18/20jurisdiction_fipsThe jurisdiction’s FIP Series (FIPS) codealldistrictThe precinct’s electoral district for that officeallcounty_nameThe name of the county that the precinct is inallcounty_fipsThe county’s FIPS code2016county_ansiThe county’s American National Standards Institute (ANSI) code2016county_latThe county’s latitude2016county_longThe county’s longitudeallstateThe name of the state that the precinct is inallstate_poThe state’s official postal code abbreviationallstate_fipsThe state’s FIPS code18/20state_cenThe state’s census codeallstate_icThe state’s Inter-university Consortium for Political and Social Research code18/20dataverseAn indicator cataloguing where we store the data in our public repository18/20readme_checkAn indicator that an issue with the state’s data is noted in the README file2016candidate_normalizedStandardized candidate name (candidate is not standardized in 2016)2016candidate_partyThe candidate’s official party (can be distinct from nominating party)2016candidate_lastThe candidate’s last name2016candidate_firstThe candidate’s first name2016candidate_middleThe candidate’s middle name2016candidate_fullThe candidate’s full name2016candidate_suffixThe suffix of the candidate’s name, if they have one2016candidate_nicknameThe candidate’s nickname, if they have one2016candidate_opensecretsThe candidate’s OpenSecrets ID2016candidate_wikidataThe candidate’s WikiData ID2016candidate_fecThe candidate’s Federal Election Commission ID2016candidate_fec_nameThe candidate’s name as listed with the Federal Election Commission2016candidate_googleThe candidate’s Google Knowledge Graph ID2016candidate_govtrackThe candidate’s GovTrack ID2016candidate_icpsrThe candidate’s ICPSR ID2016candidate_maplightThe candidate’s MapLight IDSome of the variable names are slightly different between 2016 and the other two datasets, but not enough to be ambiguous.How do we acquire all of this information? The preferred source of election results is each individual state in the country. The reason is that administration of elections in the United States is highly decentralized, and states are responsible for counting and reporting the votes that were cast in any election, even elections for federal offices. However, states vary widely in their data reporting practices.The simplest situation is when a state supplies a single file that can be downloaded by the public and contains enough information to fill out all of the required variables listed in Table 2. However, data collection is almost always more complicated than that. Sometimes states collect precinct-level data, but do not distribute them publicly, and they may or may not supply those data upon request. Even when they are publicly available, they might not be supplied as datasets; for example, results are sometimes reported only in a web app, which must be parsed using a browser to translate the results into dataset format. If data are not available online, it is sometimes possible to obtain them by directly contacting the state government, though sometimes states cannot share all of the necessary data even on request. Election results also often omit essential data, such as which office a candidate is running for, or what party a candidate is affiliated with. Frequently, election results are reported individually by sub-state bodies like county governments, and then aggregated by the state. In these cases the data for each county might use systematically different styles for recording the same information, or make independent mistakes such as typographical errors in candidate names, and an entire county may even be missing because it did not report precinct-level results to the state. Then, any essential data that are missing must be joined on from some other source. States will also often split their data into multiple files, for example by supplying all the results for the US Senate election in one file and all the results for governor in another file, and it is common to split results up by geographical divisions like counties. In many cases states will do both, and offer a separate file for every office in every county, or a separate file for every congressional district. Sometimes this means that there are dozens of files that need to be combined, which is not always a simple situation of automatically merging them, since these files may or may not share exactly the same format.In order for us to use the data from a state, the state must supply a certain minimum amount of information. Geographically, we require a unique identifier for every precinct; from there, we can infer all of the necessary identifying information for larger geographies like counties. For every race, the state also needs to provide candidate names, and the number of votes received by those candidates. In the case of ballot questions, we require the options on the ballot, which we track as if they were candidates running for an office (so that, for example, a ballot question of the form “Should the tax on X be raised?” will have candidate name values corresponding to the options people can choose, such as “YES” and “NO”). The remaining information can be constructed using lists that are generally publicly available. For example, in some cases candidates’ parties might not be included in the precinct-level data, and in those cases they need to be merged in using other publicly available datasets.Because of the number and severity of possible data problems, in some cases a state simply does not provide sufficiently complete or accurate precinct-level data. In such cases, raw precinct-level election results are sometimes available from OpenElections, an organization that coordinates the collection of election results using a combination of automatic scraping, contacting state and local governments, and entering data manually34 (the OpenElections effort is distinct from ours in that they focus on collecting precinct-level election results, often acquiring data in cases where intensive work is required to obtain the data from states or even from county-level governments, whereas we focus on standardizing and quality assuring the data).The sources of our data, and the formats that we acquired the raw data in, are described in Table 3 for the two more recent elections in our dataset (2020 and 2018, which were a presidential and a midterm election year respectively). The table summarizes where the original datasets were acquired, whether the election results themselves omitted any of the necessary information and needed to be combined with other data, what format the data were supplied in, and whether the datasets were separated out by some characteristic below the state level and had to be merged to create a statewide dataset.Table 3Data sources.StateSource 2020Availability 2020Added 2020Type 2020Split 2020Source 2018Availability 2018Added 2018Type 2018Split 2018AKgovdownloadgeocsvgovdownloadcsvALgovdownloadxlsgeogovdownloadxlsgeoARgovdownloadxlsgeo, officegovdownloadxlsgeo, officeAZgovdownloadxmlgovdownloadtabgeoCAgovdownloadcsvOEdownloadgeocsvgeoCOgovdownloadxlsgovdownloadcandxlsCTgovdownloadcsvgeo, officegovdownloadcsvgeo, officeDCgovdownloadmultigovdownloadmultiDEgovweb onlygeoofficegovdownloadcandcsvFLgovdownloadpdfgeogovdownloadtabGAgovdownloadcsvgovdownloadgeocsvstageHIgovdownloadcsvgovdownloadcsvIAgovdownloadgeoxlsgeo, officegovdownloadxlsgeo, officeIDgovdownloadxlsofficegovdownloadxlsILgovdownloadcsvgeogovdownloadgeocsvgeoKSgovrequestxlsgovdownloadgeoxlsKYgovdownloadxlsgeogovweb onlyLAgovdownloadxlsgovdownloadxlsgeo, officeMAgovdownloadcsvofficegovdownloadcsvofficeMDgovdownloadcsvgovdownloadcsvgeoMEgovdownloadxlsgovdownloadxlsofficeMIOEdownloadcsvgovrequesttabmultiMNgovdownloadxlsOEdownloadcsvMOOEdownloadcsvOEdownloadcsvMSOEdownloadcsvOEdownloadcsvMTgovdownloadxlsgeogovdownloadxlsNCgovdownloadcsvgovdownloadtabNDgovweb onlyofficegovdownloadmultigeo, officeNEgovweb onlyofficeofficegovdownloadxlsgeo, officeNHgovdownloadgeoxlsgeo, officegovdownloadgeoxlsgeo, officeNJgovdownloadgeopdfgeoOEdownloadcsvgeoNMgovdownloadgeoxlsofficegovdownloadxlsofficeNVgovdownloadpartymultigovdownloadpartymultiNYOEdownloadcsvOEdownloadcsvOHgovdownloadxlsgovdownloadxlsofficeOKgovdownloadmultigovdownloadmultiOROEdownloadcsvOEdownloadcsvPAgovrequestcsvgovrequestcsvRIgovweb onlygeo, officegovweb onlygeo, officeSCgovdownloadcsvOEdownloadcsvSDgovdownloadpdfOEdownloadcsvTNgovdownloadxlsgovdownloadxlsTXgovdownloadcsvofficegovweb onlymultiofficeUTOEdownloadcsvOEdownloadcsvgeoVAgovdownloadcsvgovdownloadcsvVTgovdownloadxlsofficeOEdownloadcsvWAgovdownloadcsvgovdownloadcsvgeoWIgovdownloadxlsofficegovdownloadxlsofficeWVOEdownloadcsvOEdownloadcsvWYgovdownloadpdfgeogovdownloadpdfgeoSource: gov = government, OE = OpenElections. Avail.: download = public, request = by request, web = in-browser. Added: missing geographic, office, party, or candidate details. Type: multi = multiple formats. Split: how files are split up.Table 3 shows that, in 2020, we were able in 42 out of 51 cases to acquire high quality precinct-level election data from the branch of the state government that is primarily associated with administering elections (and in California, those data were available from the state’s redistricting commission). In 7 of the remaining 8 cases, we acquired data from OpenElections. There is just one case, Indiana, for which we could not recover precinct-level election results in 2020 (many of Indiana’s counties simply did not report precinct-level election results in 2020). In 2018, 38 datasets were available from state election administrations. Of the remaining 13 datasets, we have published 11 using data from OpenElections. The remaining two are Indiana and New York, for which the available data have sufficiently incomplete or inaccurate vote counts that they are still pending final cleaning and quality assurance. In these counts we have included states like New Jersey and Maine, where data were released at the township level, as nevertheless successfully releasing sufficiently granular elections data to be included in our dataset.In addition to listing where the data were acquired, Table 3 also identifies any supplementary sources needed to fill in missing information, and what format the data were originally in. The table shows that there is a wide range in how ready the original datasets are for cleaning, standardizing, and incorporating into a national dataset. Hawaii is an example of a particularly straightforward state: in both 2018 and 2020, the state government publicly posted a single comma-separated file that contained election results for every candidate in every precinct. But in several states we found the opposite extreme, in which data were made available only through in-browser web apps or PDFs, split up by office and county, and missing crucial information.Some of the information in Table 3 mirrors Tables A1 and A2 in a description of OpenElections data sources34, but Table 3 includes information not in those tables and vice versa (and some differences between the two tables showcase the fluidity of states’ reporting practices, which might change even across a few weeks within the same election).StandardizationOnce a state’s data have been collected and merged into a single spreadsheet, the next task is to standardize them. In order for the datasets to be merged into one national dataset, they need to contain the same variables, and many variable values also need to be standardized.To see why variable values may need to be standardized, consider for example the case of candidate names. Different states, and even the different reporting units within one state, may submit very different formatting of candidate names. The reason is that candidate names are often entered manually by different people in different reporting areas, and in addition to typographical errors, the person responsible for entering these data in one area might choose a different convention than someone in another area.In 2020, for example, Pennsylvania recorded a vote for President Biden in its presidential contest as a vote for the candidate named “BIDEN, JOSEPH ROBINETTE”, whereas Arksansas recorded it as a vote for “Joseph R. Biden/Kamala Harris”. These names need to match across states. But the same problem might occur at the county level, or it might occur in just the cases where a person who entered the data made one systematic mistake. In Georgia’s 2020 precinct data, for example, the name of US Senate candidate Matt Lieberman appeared in 14,035 rows, but in Franklin County his name was misspelled 40 times as “Matt Lierberman”. That raw data file contained 774,906 rows, so a mistake that occurs in one candidate name 40 times cannot be reliably identified by eye. The number of candidates listed in Table 1, and the number of precincts those candidates appear in, demonstrates the scale of this challenge: candidate name matching is not a matter of simple find and replace actions, but requires automated fuzzy matching across the whole dataset. So, we first convert all candidate names to uppercase (a practice that we adopted in our 2018 and 2020 data), which greatly reduces the number of errors in matching, without meaningfully reducing the usability of the dataset. Then we use the default extract function from the process module of the fuzzywuzzy Python library, with a sensitivity cutoff that typically shows every collection of strings which either contain large amounts of shared text, or are separated by a few substitutions or insertions.In addition to standardizing variable values, we also standardize what variables are included. Often the variables of interest need to be inferred, or are combined into one variable and must be teased apart. For example, a state may provide the precinct designation as “countyName_precinctName”, and then the precinct name and county name need to be split into two different variables, and the standard county FIP Series (FIPS) code added. Another common issue is that party names, or the word “writein”, are often included in the raw data as part of a candidate name, but we store each of these in a separate variable.Finally, in some rare cases, states or other research organizations release shapefiles that map the boundaries of the precincts in a state. These spatial data are particularly important for studying the spatial problem of redistricting. When such files are available, we attempt to retain any geographic information, such as the particular formatting of precinct names, that would be needed to match our precinct-level election results onto the precinct shapefiles. When such data are not available, we avoid removing information from precinct names whenever possible, in the interest of making it possible to match to any geographic files that might be made available after we release our data; excising information that might initially appear unnecessary might hinder attempts by end-users interested in matching our tabular data to spatial precinct data that subsequently becomes available.Importantly, our standardization efforts are aimed at standardizing data within election years, but there is no general way to match precinct-level election results across election years. There is no requirement for a precinct to have the same name from one election to the next, and states may create, abolish, or rename precincts between elections, with or without providing a crosswalk file that matches new precinct names to old precinct names. Worse, precinct boundaries frequently change, so a precinct with the same name in roughly the same location may contain a different population from one election to the next32. We therefore emphasize that users of our datasets are not encouraged to join precincts by name across elections, unless they have verified with a separate source (such as the precinct shapefiles maintained by the United States Elections Project) that the name identifies the same precinct in both years and that the geography of the precinct did not change.Data RecordsOur 2016, 2018, and 2020 precinct-level American election result datasets are each available for download on a public repository. In 2016 and 2020, the data have been published as Harvard Dataverse records. The 2018 data are available on a public GitHub account while the formatting of those datasets is being updated to the standardized format used for the 2020 data. For ease of use, each of these records are divided into datasets in several different ways.The data records corresponding to elections in 2020 are available on Harvard Dataverse and are organized as follows: 2020 US President election results35, 2020 US Senate election results36, 2020 US House election results37, 2020 state-level election results38, and individual datasets for each state listing all of the election results there39.For 2018 elections, the data are currently stored on a GitHub repository, although they will eventually be moved to the Harvard Dataverse40.For 2016, the data are available on Harvard Dataverse, in the following individual data records: 2016 US President election results41, 2016 US Senate election results42, 2016 US House election results43, 2016 state-level election results44, and 2016 local-level elections45.In addition to these flat files, the data are also available for download in SQL database format46.Technical ValidationWe have developed a procedure for ensuring the quality of our datasets that emphasizes reproducibility, and involves many large-scale automated validation checks. In our cleaning process, one person cleans and standardizes a dataset, and then saves a copy of the code that they used. Then a second person runs a standard battery of quality assurance checks on the output of that cleaning code, and reports to the first person any issues that the quality assurance checks identified. These two people then iterate: the first person updates their cleaning code, and the other runs the quality assurance check on its output, until the checks do not find any remaining problems. Not only is the code (and every draft of the code before the finished version) saved in a GitHub repository, but the discussion of any issues that arose during the quality assurance process are also saved as comments in that repository, so that any future issues can be traced to their origin and addressed without re-doing any of the initial cleaning. Because this procedure was developed and implemented over the course of our data collection efforts, we can consistently supply replicable code and raw datasets for the 2018 and 2020 datasets, but we cannot guarantee that full replication scripts are available for the 2016 dataset.The quality assurance process is largely implemented as an automatic engine in Python. For every variable, the engine checks that the variable exists and is formatted according to the codebook, and also identifies a variety of common data problems. Table 4 lists the checks that are performed, the purpose of each check, and the variables that each check applies to.Table 4The automated checks performed by our quality assurance engine, the purpose of each check, and the variables that they apply to.TypePurposeVariablesexistencechecks that all variables existallcharacterchecks for suspicious string characterscandidate, county_name, dataverse, district, jurisdiction_fips, jurisdiction_name, magnitude, mode, office, party_detailed, party_simplified, precinct, special, stage, state, state_cen, state_fips, state_ic state_po, votes, writeinsimilaritychecks for suspiciously similar valuescounty_name, county_FIPS, dataverse, district, jurisdiction_fips, juristiction_name, magnitude, mode, party_detailed, party_simplified, special, stage, state state_cen, state_fips, state_ic, state_po, writeindictionarychecks values match a definitive listcounty_fips, dataverse, date, party_simplified state_cen, state_fips, state_ic, state_pouniquenesschecks values are uniquemagnitude, office, state, state_cen, state_fips, state_ic, state_po, writeinnumericalchecks numerical constraintsvotesduplicatesfinds duplicated and near-duplicated rowsallIn the interest of space we list the variable names here; the meaning of these variables can be understood by consulting Table 2.The two most important types of checks are character checks and similarity checks. Character checks identify any unexpected symbols inside a variable value; for example, it is likely a mistake if a candidate name contains a “%” symbol, or if a vote total contains a non-numeric character. There are two types of similarity checks. General similarity checks compare the values of variables to a list of common words that are frequently misspelled. For example, a race in Texas in 2020 was described as electing a “JUSTIVE” rather than a “JUSTICE”. Substitution errors in common words can be caught by comparing the strings in the raw data to a list of words that frequently appear in election data. Specific similarity checks, on the other hand, compare the values within a variable to one another. We implement these in two ways: through fuzzy string matching, and also by simply printing out the unique values of a variable in alphabetical order and noting any nearly duplicated names. In some cases this catches typographical errors, like the spelling of Matt Lieberman as “Matt Lierberman”. Many of the cases these similarity checks flag, however, are different ways of writing the same information, which need to be standardized so that the values match; for example, these checks would reveal that the name of a US Senate candidate from West Virginia is rendered variously as “Joe Manchin”, “Joseph Manchin”, and “Joseph Manchin III”.In some cases, we have the opportunity to check variables against a dictionary of definitive values. An example is state FIPS codes, which are the numerical identifiers that the U.S. Census Bureau has assigned to each state and county. Since each state and county has just one unique correct FIPS code, we can enforce that every value of this variable is exactly correct. It is also sometimes useful to check for unique correspondences. For example, usually each type of office corresponds to just one magnitude (the number of election winners). It would be difficult to enforce that each office is associated with exactly the correct magnitude — state house races in Michigan should typically have a magnitude of 1, but state house races in New Jersey should typically have a magnitude of 2, except perhaps in the case of certain types of special elections — but a uniqueness check can identify cases where the same office within the same state corresponds to more than one magnitude value, which is likely a mistake. For numerical values, we can also check certain constraints; for example, only some numbers represent legitimate vote totals. Finally, in a dataset where each row is intended to represent a unique precinct-candidate combination, not only should no rows ever be exact duplicates of each other, but there should almost never be two rows with the same candidate name and the same precinct name (with a few exceptions, for example if a state separately reports the vote totals that an electoral fusion candidate received under each of the parties that nominated them). A final check identifies any rows that are either duplicates or near-duplicates of each other.In addition to all of these checks, there is another crucial type of check that can be only semi-automated: aggregation checks. States release vote count totals at various higher levels of aggregation than the precinct, and the results of all races at their highest level of aggregation (the full electoral constituency) is common knowledge once election results have been certified. So, when we add together the vote totals in each precinct within a given county or state, the resulting sum should match the official vote total in that area. Of course, this does not catch every mistake, because errors might cancel each other out (over-counting a candidate’s vote total in one precinct and then under-counting that candidate’s total by the same amount in another precinct within the same county will still produce the correct county-level total), but this check will catch net errors in a candidate’s vote total across some larger geography.Aggregating our vote counts to compare them to published results is not completely straightforward, because the format in which automated counts are published varies widely, so we have built routines for automatically aggregating vote counts to any number of a variety of common state-published formats. But there is a more serious reason that this check cannot be automated in general: the names of counties and (especially) candidates in the available county-level election results do not always exactly match their names in our final precinct-level datasets, and ensuring that such a large number of strings do match would be nearly tantamount to cleaning county-level election results in addition to the precinct-level election results.Nevertheless, we base a simple automated first pass on the fact that it is much easier to ensure that all county names match between the files than to make all of the candidate names match. We begin by running an aggregation checking script in R that simply compares the list of vote totals that each candidate received in the official county-level data to the list of candidate-by-candidate sums over precinct-level vote totals. Without consulting which candidate received each vote total, it simply reports any discrepancies between those two lists. So if (for example) our precinct-level data report that there is some candidate who received 800 votes across all of the precincts in a county, and the county-level results report that there is a candidate who received 801 votes, then we can check by eye whether the datasets are referring to the same candidate, since in this example it is likely that our precinct-level vote total for some candidate differs from their county-level total by one vote. This automated first pass helps to identify counties with major problems, but of course it is not sufficient on its own to identify every issue. We therefore also compare our data to official county-level results by eye. When we find major discrepancies, we reach out to the state that provided the data (where applicable) and request clarification, and in some cases they are able to explain or resolve the discrepancy.Counties are just one possible unit of aggregation, and indeed we can use the aggregation check idea to determine the accuracy of the precinct-level data across any larger geography. We will conclude this article by conducting aggregation checks on all races for federal office in the 2016, 2018, and 2020 datasets. However, we should be clear that there are many reasons that vote totals may be unavoidably different at different levels of aggregation. Probably the biggest reason is that states often do not officially certify precinct-level results (although when they do, we use the certified totals), and in many cases the official vote counts either include some ballots that were not included in the unofficial counts, or exclude some ballots that were included unofficially. This is especially difficult to resolve when there is legitimate uncertainty about precise vote totals; for example, votes that are the topic of pending court challenges may be legitimately counted when the precinct-level dataset is produced and equally legitimately not counted in a county-level dataset. Second, there are sometimes small clerical errors in the announced vote counts, but it is not possible to ascertain whether the precinct-level values are erroneous or the higher-level values are. Third, it is possible for the values to not match for reasons to do with how votes are reported. Some states, such as Florida, require the suppression of precinct-level results when the number of voters is below a certain threshold. Still others induce random noise into precinct returns in low-turnout precincts. Fourth, precinct-level datasets sometimes do not identify every candidate who receives a write-in vote, but those votes may be counted towards the candidate’s official vote total. Finally, even though precincts typically partition a single county that completely contains them, there are some exceptions. For these reasons and many others, it is not generally possible to create a precinct-level dataset that precisely adds up to the official county- or state-level data. However, the result certainly should be close. In cases where discrepancies simply cannot be avoided, we provide a readme file that identifies the discrepancy and, where possible, notes its cause and why it has not been resolved.Despite these unavoidable problems, Table 5 shows that our precinct-level results for federal races aggregate all the way to the national level with extremely high accuracy. We check the official nationwide vote totals for both major parties in the three types of federal election — presidency, US Senate, and the US House of Representatives — against the totals obtained when summing our precinct-level data up to the national level. This generates sixteen comparisons: four presidential totals, and six each of the Senate and the House. The “accuracy” percentage a that we report is\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$a\equiv 100 \% -\frac{| r-f| }{f}\cdot 100 \% $$\end{document}a≡100%−∣r−f∣f⋅100%where r is the sum of our precinct-level votes for relevant offices, and f is the official total. Table 5 shows that every one of the sixteen totals is at least 99.5% accurate, and about half are at least 99.9% accurate. Out of tens of millions of votes cast for each party in each of these contests, the discrepancies are tens of thousands of votes in most cases.Table 5The sum of our precinct-level data compared to the official nationwide vote totals for each major party in each type of federal race in 2016, 2018, and 2020.YearRace typeCandidate/PartyStatesOur totalOfficial totalPercent accuracy2016US PresidentHillary Clinton51/5165,851,67665,853,51499.997%2016US PresidentDonald Trump51/5162,980,40562,984,82899.993%2016US SenateDemocrats35/3550,680,32450,610,70499.862%2016US SenateRepublicans35/3540,848,58540,788,13199.852%2016US HouseDemocrats51/5159,303,97159,327,50299.960%2016US HouseRepublicans51/5160,002,67859,945,74099.905%2018US SenateDemocrats32/3447,576,06447,394,57399.619%2018US SenateRepublicans32/3431,883,64331,895,33799.963%2018US HouseDemocrats49/5155,902,33155,648,03099.543%2018US HouseRepublicans49/5147,719,86247,589,64799.726%2020US PresidentJoe Biden50/5180,035,36080,026,50899.989%2020US PresidentDonald Trump50/5172,495,66472,486,63599.988%2020US SenateDemocrats35/3537,706,26437,765,39599.843%2020US SenateRepublicans35/3539,300,42439,257,32999.890%2020US HouseDemocrats50/5176,175,50476,159,11699.978%2020US HouseRepublicans50/5170,807,54470,727,83199.887%The percentage is calculated using the equation specified in the text. Here it is rounded to five digits (the smallest number of digits for which no total rounds up to 100%). The states column shows the number of states (plus DC) included in our dataset out of the number of states that the race took place in. As explained in the text, some of these states are excluded from the total in the table because partisan comparisons are not coherent in every race in the country (for example in the case of run-offs that are not general elections with simple partisan labels).We once again emphasize that aggregation checks cannot guarantee that our data are almost completely devoid of errors, because as we have discussed precinct-level errors might cancel each other out. What this analysis does demonstrate, however, is that our data are almost completely devoid of systematic errors by party within major federal races.Another caveat is that we have had to exclude some races from these comparisons. Which contests are missing and why? Indiana did not consistently release precinct-level vote totals in 2020 (some counties in Indiana did release precinct-level results, but many did not), so it is not possible to include. Our 2018 data do not currently include Indiana, New York, or the Maine House of Representatives election that was decided using Instant Runoff Voting; these are all excluded from the totals in Table 5. The totals in the table also exclude some congressional races (the 2020 races in Georgia, the 2018 pre-runoff races in Louisiana, and races in Pennsylvania) which have complicated election structures that make party-by-party comparisons to official totals infeasible, though our candidate-level totals for these races are all individually accurate. To also give a sense for the state-level variation in accuracies, Table 6 compares the sum of our precinct-level vote totals in each state to the official state-level vote total, for both major candidates in the most recent presidential election.Table 6Accuracy of our vote totals for major party presidential candidates at the state level.StateTrump 2020 OursTrump 2020 OfficialTrump 2020 AccuracyBiden 2020 OursBiden 2020 OfficialBiden 2020 AccuracyAK189,951189,951100%153,778153,778100%AL1,441,1701,441,170100%849,624849,624100%AR760,647760,647100%423,932423,932100%AZ1,661,6861,661,686100%1,672,1431,672,143100%CA6,006,5186,006,42999.999%11,110,63911,110,25099.996%CO1,364,6071,364,607100%1,804,3521,804,352100%CT714,697714,71799.997%1,080,6801,080,83199.986%DC18,58618,586100%317,323317,323100%DE200,603200,603100%296,268296,268100%FL5,668,7165,668,731100%5,297,0365,297,045100%GA2,461,8372,461,85499.999%2,474,5072,473,63399.965%HI196,864196,864100%366,130366,130100%IA897,672897,672100%759,061759,061100%ID554,119554,119100%287,021287,021100%IL2,446,8912,446,891100%3,471,9153,471,915100%KS771,406771,406100%570,323570,323100%KY1,326,4181,326,64699.983%772,285772,47499.976%LA1,255,7761,255,776100%856,034856,034100%MA1,167,2021,167,202100%2,382,2022,382,202100%MD976,414976,414100%1,985,0231,985,023100%ME360,737360,737100%435,072435,072100%MI2,649,2342,649,85299.977%2,801,4692,804,04099.908%MN1,484,0651,484,065100%1,717,0771,717,077100%MO1,718,7361,718,736100%1,253,0141,253,014100%MS756,764756,764100%539,398539,398100%MT343,602343,602100%244,786244,786100%NC2,758,7732,758,775100%2,684,2922,684,292100%ND235,595235,595100%114,902114,902100%NE556,846556,846100%374,583374,583100%NH365,660365,660100%424,937424,937100%NJ1,883,3131,883,27499.998%2,608,4002,608,33599.998%NM401,860401,89499.992%501,552501,61499.988%NV669,480669,89099.939%703,186703,48699.957%NY3,252,2333,244,79899.771%5,245,0675,230,98599.731%OH3,154,8343,154,834100%2,679,1652,679,165100%OK1,020,2801,020,280100%503,890503,890100%OR958,448958,448100%1,340,3831,340,383100%PA3,379,3213,377,67499.951%3,457,3433,458,22999.974%RI199,922199,922100%307,486307,486100%SC1,385,1031,385,103100%1,091,5411,091,541100%SD261,043261,043100%150,471150,471100%TN1,852,4751,852,475100%1,143,7111,143,711100%TX5,889,0225,890,34799.978%5,257,5195,259,12699.969%UT865,139865,140100%560,282560,282100%VA1,962,4301,962,430100%2,413,5682,413,568100%VT112,797112,70499.917%242,828242,82099.997%WA1,584,6511,584,651100%2,369,6122,369,612100%WI1,610,0651,610,18499.993%1,630,6731,630,86699.988%WV548,463545,38299.435%235,984235,984100%WY193,559193,559100%73,49173,491100%Ours is our total, official is the official total, and accuracy is the accuracy percentage.Usage NotesReadmes are provided alongside the datasets and specify three important types of information. First, they describe any errors or data limitations that were identified in the process of collecting, standardizing, and assuring the quality of the data, but which for any reason could not be resolved. An example is cases where precinct-level vote counts differed from county-level vote counts and could not be reconciled.Second, they identify missing information. For example, we typically include vote counts for write-in candidates, but in the file for our 2020 precinct-level election results we identify some states where write-ins were not consistently reported.Third, the readme files note the inclusion of certain types of meta-information that prevent the dataset from being immediately interpreted as containing candidate-precinct vote totals. For example, the readme for Michigan in 2018 notes that the state’s original dataset included “statistical adjustment” rows, which do not correspond to any real precinct, and have a precinct value of “9999”. Another common example is when states report data in such a way that candidates are assigned 0 votes in precincts that they did not contest, which cannot be cleaned in general, because there is often no way to differentiate at scale between those (many) precincts where a candidate legitimately received 0 votes, and precincts that a candidate did not actually contest and was nevertheless assigned 0 votes in by the state’s precinct-level data. In these cases the readme warns users to be wary of these fictitious candidate-precinct combinations when computing statistics.