SkillAtlasSkill 详情

election-data-source-countypres

Security audit: baseline 52/52 CLEAN

审核状态:已审核Quality 72Security 70

复制安装命令

用 Codex 或 Claude 安装复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它先审查 Skill 页面再帮你安装。

复制前请先查看来源、License 和安全提示。

项目 README

来源文件:README.md

抓取于 2026年8月5日

Awesome GitHub stars License: CC BY-SA 4.0 PRs Welcome Validate catalog OpenSSF Scorecard Security audit: baseline 52/52 CLEAN Rigor coverage Powered by StatsPAI

Auto-Empirical Research Skills (AERS)

📌 文档结构(2026-07-22 起): 本文件是中文默认入口 —— banner + badges + 信任面 + 9 阶段流水线速览 + 76 行合集总表。 每个合集的完整描述、按用途分组、精确数字、验证方法在 docs/CONTENT_ZH.md(扩展正文,总表行内的 → 直接跳转到对应锚点)。

English version: README-en.md · 中文扩展正文:docs/CONTENT_ZH.md · README-zh-CN.md 已弃用(重定向占位)

🌐 语言: English | 简体中文(默认) | 繁體中文 | 日本語 | 한국어


CoPaper.AI Stanford REAP - Center on China's Economy & Institutions

Stanford REAP × CoPaper.AI · 实证研究 AI 工具的学术工业级产品
由斯坦福实证研究方法论团队打造,覆盖从数据清洗到顶刊投稿的完整工作流



实证研究智能体技能大全封面图

🚀 New here? Open the Skill Search → to filter all 1,096 skills by method, stage, language, and license. The 5-minute tour (make quickstart) prints the same picture in your terminal.

🇨🇳 中文用户从本文件开始(流水线速览 + 76 行总表),每个合集的完整描述见 docs/CONTENT_ZH.md。📖 English readers: see README-en.md.


信任面 · Trust surface (rigor stats)

Rigor laneCountWhere
Numeric benchmark tasks — gold values recomputed from real data each run17benchmark/
Behavioral eval scenarios / rubric items37 / 183eval-harness/

Full trust overview: docs/TRUST.md · docs/RIGOR_COVERAGE.md


中文文档结构

中文内容分两级维护,各司其职:

  • 本文件(README.md,GitHub 默认入口):banner、badges、信任面、9 阶段流水线速览、76 行合集总表。
  • docs/CONTENT_ZH.md(扩展正文):每个合集的完整描述(#skill-NN 锚点)、按用途分组、精确数字、2 分钟验证、三层信任、旗舰流水线详解、贡献与引用。总表行内的 → 直接跳到对应锚点。
  • 其他语言:README-en.md · README-zh-TW.md · README-ja.md · README-ko.md

[!NOTE] 维护规则: 改合集总表 → 本文件与 CONTENT_ZH.md 的锚点表两处同步;改合集详情 / 分组 / 数字 → 只改 docs/CONTENT_ZH.md。统计数字(合集数 / skill 数)以 catalog/skills.json 为准,由 make validate 的 readme-stats 检查器守护。

贡献者(Contributors): 提交前请在本地跑通完整门禁 make check(catalog 校验 + 链接 + 单元测试 + eval-harness + benchmark)。详见 CONTRIBUTING.md。

旧版归档: README-zh-CN.md 已弃用,仅作向后兼容的重定向占位。


🚀 从一个 idea 到一篇论文:社科实证研究 · 端到端流水线(全自动、可介入)

AERS 不只是 76 个散装 skill —— 它能陪你走完一篇论文。 从模糊 idea → 选题精炼 → 文献综述 → 数据获取 → 识别策略 → 估计建模 → 稳健性审计 → 出版级表格 / 图形 → 写作与同行评审 → 降 AIGC → 投稿。端到端、全自动、每一步都可被人介入(中间任何一步你都可以接过去手工改方法、补变量、加稳健性,再让流水线自动接上跑)。

9 阶段流水线 · 每一步都覆盖到具体 skill

#阶段关键 skills(点合集名进目录,→ 进完整说明)
1️⃣选题精炼 — Agent 把模糊想法收紧成"可证伪 + 可执行"的研究问题· 25 Diverga · 33 claude-scholar · 05 research-superpower · 11 compound-science
2️⃣文献综述 — 检索 · 筛选 · PRISMA 流程 · 批判性阅读 · 主题分析· 36 literature-review-skill · 24 academic-research-skills · 59 openalex-skill · 68 research-productivity-skills · 53 thematic-analysis
3️⃣数据获取 — 公开数据库 · API · 网页抓取 · 数据清洗· 33 claude-scholar · 68 research-productivity-skills · 32 stata-skill · 57 edgartools
4️⃣识别策略 — DiD / RD / IV / SCM / DML / matching 全覆盖· ⭐ 00 StatsPAI 🔥 · 10 causal-inference-mixtape · 13 MixtapeTools · 51 CausalPy · 63 scientific-agent-skills
5️⃣估计建模 — Python / Stata / R 三栈,900+ 估计器· ⭐ 00.1 Full Empirical · Python · ⭐ 00.2 Full Empirical · Stata · ⭐ 00.3 Full Empirical · R · 40 pyfixest · 39 marginaleffects · 09 awesome-econ-ai
6️⃣稳健性审计 — 复现包检查 · Honest-DiD · R&R 模拟· 41 sewage-econometrics-check · ⭐ 50 AER-skills · 21 AI-research-feedback
7️⃣表格 & 图形 — 期刊出版级排版 · LaTeX 嵌入· ⭐ 00 StatsPAI · 07 AI-Research-SKILLs · 33 claude-scholar · 08 latex-document-skill
8️⃣写作 & 同行评审 — LaTeX / Quarto · 仿审稿人 · 校对· 06 stats-paper-writing · 04 scientific-writer · 22 christopherkenny-skills · 38 academic-proofreader · 56 econ-writing-skill · 16 clo-author
9️⃣降 AIGC & 投稿 — 知网 / 万方 / Turnitin / 23 类 AI 痕迹模式· ⭐ 48 de-AIGC-skills 🇨🇳🇬🇧 · 44 humanizer_academic · 45 deslop · 46 stop-slop · 47 avoid-ai-writing · 49 humanize-chinese

🎼 元编排:⭐ 69 Paper-WorkFlow —— 一键串起来

Paper-WorkFlow 是 AERS 的"指挥棒",它把上面 9 个阶段的 skill 串成 一条按键即运行的端到端流水线。 你在 IDE 入口给它一句自然语言:

"开一个新论文项目:空气污染与中国劳动力市场,CS 设计 + 省级面板"

它会自动按顺序调:

  1. ⭐ 00 StatsPAI → sp.csdid(...) 给出 CS-DID 估计草案 + 写出估计方程与识别假设
  2. 33 claude-scholar → 抓变量定义 / 数据源候选 / 相关文献
  3. ⭐ 00 StatsPAI → 真跑 sp.feols(...) + sp.honest_did(...)
  4. 41 sewage-econometrics-check → 10 项复现包审计 + 稳健性体检
  5. ⭐ 00 StatsPAI + 07 AI-Research-SKILLs → 出 Table 1–5 + 期刊级图
  6. 38 academic-proofreader → 通读 + §comment 标"审稿人会挑刺的位置"
  7. 56 econ-writing-skill 起草初稿 + ⭐ 48 de-AIGC-skills 🇨🇳🇬🇧 + 45 deslop 过知网 / Turnitin

任何阶段你都可以手动介入 —— 上一阶段的产物全部落盘(产物-幂等 pipeline),你接过去改方法、补控制、加稳健性,再让流水线自动接下去跑。这就是"全自动 + 可介入"。

🏆 7 个 Stanford REAP × CoPaper.AI 自研 skill —— 是整个流水线的主干

⭐ Skill在流水线里的角色
00 StatsPAI 🔥因果引擎:900+ 函数,sp.causal(...) 一行跑闭环(DID / RD / IV / SCM / DML / matching)
00.1 Full Empirical · Python 📘显式 Python 栈(pandas / statsmodels / linearmodels / pyfixest)
00.2 Full Empirical · Stata 📊显式 Stata 栈(reghdfe / ivreg2 / csdid / sdid / rdrobust)
00.3 Full Empirical · R 📗显式 R 栈(tidyverse / fixest / did / HonestDiD)+ Quarto 渲染
48 de-AIGC-skills 🇨🇳🇬🇧中英双语学术降 AIGC(Turnitin AI / GPTZero / 知网 / 万方)
50 AER-skills 📕Top-5 经济学投稿套件:识别 → 稳健性 → R&R
69 Paper-WorkFlow 🧭元编排器,把上面 9 个阶段串成一键流水线

为什么挑这 7 个?因为它们的行为都被基准钉死了 —— 不是营销口径,是对着已知答案反复跑过验证过的(17 项数值 benchmark + 37 项行为评测 ↗)。

看到这里 —— 完整 76 行合集目录

↴ 直跳到下方 76 行总表(每个合集带 #skill-NN 锚点)。如果你更关心"这些 skill 怎么用"而不是"有哪些 skill",看 📘 中文唯一权威正文 里的「按用途分组」与「旗舰流水线」两节。


🧰 76 个核心 Skills 合集一览(00 → 72,编号连续无空缺)

打开仓库 → 看见整座库。 全部 76 个合集 · 1,096 个 skill,每一个都已 vendor 进本仓库,由 catalog/skills.json 跟踪。⭐ = Stanford REAP × CoPaper.AI 团队自研的 skill;其余为精选、经安全审计的社区作品。

主题图例 — 🚀 全流程与编排器 · 🎯 因果推断与计量经济学 · 📚 文献与研究设计 · ✍️ 写作 / 编辑 / 去 AIGC · 📑 引用 / 复现 / 同行评审 · 🛠️ 数据 / 工具 / 基础设施

点击【→】 跳转到 docs/CONTENT_ZH.md 中该合集的完整描述;点击合集名 直接打开其目录。

#合集一句话详情
⭐ 00StatsPAI 🔥因果引擎 · Agent-native Python DSL:sp.causal(...) 一行跑闭环(DID/RD/IV/SCM/DML,900+ 函数)→
⭐ 00.1Full Empirical · Python 📘显式栈:pandas · statsmodels · linearmodels · pyfixest→
⭐ 00.2Full Empirical · Stata 📊reghdfe · ivreg2 · csdid · sdid · rdrobust 复现包→
⭐ 00.3Full Empirical · R 📗tidyverse · fixest · did · HonestDiD + Quarto 渲染→
01academic-paper-skills大纲 → 手稿写作 + 7 维审稿人模拟→
02research-skills医学影像综述、提案、论文转幻灯片→
03scientific-skills假设生成 + 28 个科学数据库→
04scientific-writer引用管理 + 科学写作→
05research-superpower系统化检索、筛选与引文溯源→
06stats-paper-writing端到端 LaTeX 统计论文写作→
07AI-Research-SKILLs发表级 ML 图表、LaTeX、引文核验→
08latex-document-skill创建 / 编译任意 LaTeX 文档为 PDF→
09awesome-econ-aiPython 面板数据分析(linearmodels)→
10causal-inference-mixtapeDID / IV / RDD / SCM 模板(Cunningham)→
11compound-science面向定量社会科学的贝叶斯估计→
12claude-code-my-workflow提交 → PR → 合并的研究工作流(Emory)→
13MixtapeToolsCunningham 的因果推断工具集与讲义→
14research-starterR 中的 IV / DiD / RDD,含完整诊断→
15social-science-researchR 或 Python 端到端数据分析→
16clo-author多代理数据分析(R / Stata / Python)→
17DAAF安全意识代理框架(32 条 deny rule)→
18stata-accounting来自 126 篇 JAR 论文的实测 Stata 范式→
19vera-economic-intelligence经济情报 / 政策研究情报工作流→
20python-econ-skillDSGE / HANK 与定量经济计算→
21AI-research-feedback用 AI 同行评审生成结构化反馈→
22christopherkenny-skills面向 Quarto(.qmd)的 APSA 风格检查器→
23baygent带护栏的 PyMC / Arviz 贝叶斯工作流→
24academic-research-skills5 审稿人多视角论文评审→
25Diverga研究问题精炼器(抗模式坍缩)→
26scholar统计算法设计与文档→
27my_claude_skills经济学摘要写作指南→
28paper-replicate-agent论文复现代理演示→
29project20XXy可复现手稿 + notebook 项目→
30zirui-song-claude-skillsZirui Song 的研究辅助 Claude 技能集→
31claude-code-skillsPython 面板数据分析→
32stata-skill高性能 Stata C/C++ 插件→
33claude-scholar研究全生命周期:选题 → 综述 → 实验 → 审稿回复→
34research-companion头脑风暴、评估并决策研究方向→
35academic-writing-skills面向投稿场所的工业 AI 文献研究→
36literature-review-skill完整文献综述工作流(中文)→
37IlanStrauss-ai-skillsIlan Strauss 经济学研究 AI 工作流→
38academic-proofreader学术校对→
39marginaleffects预测、斜率与比较(R / Python)→
40pyfixestPython 中的快速固定效应估计→
41sewage-econometrics-check10 项复现包审计→
42ARIS自主「research-in-sleep」代理,端到端→
43research-plugins478 个研究插件:数据可视化、领域、基础设施→
44humanizer_academic为医学/学术手稿去 AI 味(23 类模式)→
45deslop去除 AI 写作痕迹(5 维评分)→
46stop-slop三层 AI 痕迹检测与改写→
47avoid-ai-writing审计 → 改写 → 二次审计 AI 味(留痕)→
⭐ 48de-AIGC-skills 🇨🇳🇬🇧中英双语学术降 AIGC(Turnitin AI / GPTZero / 知网 / 万方)→
49humanize-chinese检测并人性化 AI 生成的中文文本→
⭐ 50AER-skills 📕Top-5 经济学投稿套件:识别 → 稳健性 → R&R→
51CausalPy贝叶斯准实验(PyMC Labs)→
52slr-prisma系统文献综述,PRISMA 2020→
53thematic-analysisBraun & Clarke 六阶段定性主题分析→
54open-science-skills引用一致性、DOI 与论据支撑审计→
55r-skillsR 中用 brms 做贝叶斯推断→
56econ-writing-skill综合 50+ 顶级指南的经济学写作→
57edgartools查询与分析 SEC 文件→
58econstack政策简报(UK GES / AU Treasury)→
59openalex-skill通过 OpenAlex 查询 2.4 亿+ 学术作品→
60superpapers综合性实证研究支持套件→
61research-methods与预注册匹配的验证性检验→
62citation-checker对照 CrossRef / S2 / OpenAlex 核验引用→
63scientific-agent-skillsDoWhy 识别–估计–反驳框架→
64mcp-stata20 个 Stata 因果推断与复现 skill→
65game-theory-paper-writer生成并压力测试博弈论论文→
66empirical-research-skills面向大型面板的 R 性能优化→
67econfin-workflow-toolkit中国公司金融实证工作流,从提案到论文→
68research-productivity-skills论文检索、SSRN、DOI 查询、下载→
⭐ 69Paper-WorkFlow 🧭元编排器,串起整个社会科学论文流水线→
70ssci-polish ✍️SSCI / SCI 英文论文语言润色(语法、可读性、学术语气)→
⭐ 71lit-review-agent-tools 🔍文献综述工具选型 + 一键安装运行(MinerU / PaperQA2 / ASReview / STORM / MCP 服务器)→
⭐ 72Kaggle Research 🧪通过官方 CLI 安全检索 Kaggle 资源、限界下载公开数据并保留审计证据→

想看更详细的描述(主题分类、字段、统计)? 见 docs/CONTENT_ZH.md 中标注 #skill-NN 锚点的同一张表 —— 它是每个合集的完整描述所在的扩展正文。

📈 项目历程

自 2026-04 首次发布以来的主干里程碑(完整提交记录见 Commits 与 CHANGELOG.md):

---
config:
  gitGraph:
    rotateCommitLabel: false
---
gitGraph TB:
   commit id: "2026-04 首次发布"
   branch community
   commit id: "2026-05 首个社区 PR"
   checkout main
   merge community
   commit id: "2026-05 更名 AERS"
   commit id: "2026-06 插件市场"
   commit id: "2026-06 全库路由器"
   commit id: "2026-07 首个 tag" tag: "v2026.07"
   branch kaggle
   commit id: "2026-07 Kaggle 集成"
   checkout main
   merge kaggle
   commit id: "2026-08 de-AIGC 双语"
Star History Chart

Star 增长曲线(非提交数)· 由 scripts/build-star-history.py 从 GitHub API 生成并提交入库

如果 AERS 对你的工作有帮助,请引用它(CITATION.cff)并点个 Star,让更多研究者看到。


AI 是放大器,不是替代品。它替你做最耗时的"搬砖",你保留最核心的"判断"。


CoPaper.AI Stanford REAP

Stanford REAP × CoPaper.AI · 实证研究 AI 工具的学术工业级产品


扫码访问 copaper.ai
扫码访问 copaper.ai
CoPaper.AI 公众号
关注公众号「CoPaper.AI」

内置 20 个方法论 skill · 20 分钟完成实证论文 · 自研 StatsPAI(900+ 函数 / MIT 开源)

数据与 AI

中风险

  • 来源需自行核对维护者身份。
  • 包含脚本或命令调用,安装前请复核。
  • 可能需要外部 token、网络权限或第三方服务。
  • 未检测到高风险命令。
  • 扫描发现:3 条。

Codex — Git Clone 安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 克隆仓库:git clone https://github.com/brycewang-stanford/Auto-Empirical-Research-Skills.git
  3. 将 "skills/17-DAAF-Contribution-Community-daaf/dot-claude/skills/election-data-source-countypres" 文件夹复制到 Codex 的 skills 目录中。
  4. 重启 Codex 让新的 skill 生效。

Codex — 手动复制安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 从源仓库下载 SKILL.md 及相关文件。
  3. 在 Codex 的 skills 目录中创建新文件夹。
  4. 将所有 skill 文件复制到新文件夹中。
  5. 重启 Codex 让新的 skill 生效。

Claude Code — Git Clone 安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 克隆仓库:git clone https://github.com/brycewang-stanford/Auto-Empirical-Research-Skills.git
  3. 将 "skills/17-DAAF-Contribution-Community-daaf/dot-claude/skills/election-data-source-countypres" 文件夹复制到 Claude Code 的 skills 目录中。
  4. 重启 Claude Code 让新的 skill 生效。

Claude Code — 手动复制安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 从源仓库下载 SKILL.md 及相关文件。
  3. 在 Claude Code 的 skills 目录中创建新文件夹。
  4. 将所有 skill 文件复制到新文件夹中。
  5. 重启 Claude Code 让新的 skill 生效。

Cursor — Git Clone 安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 克隆仓库:git clone https://github.com/brycewang-stanford/Auto-Empirical-Research-Skills.git
  3. 将 "skills/17-DAAF-Contribution-Community-daaf/dot-claude/skills/election-data-source-countypres" 文件夹复制到 Cursor 的 skills 目录中。
  4. 重启 Cursor 让新的 skill 生效。

Cursor — 手动复制安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 从源仓库下载 SKILL.md 及相关文件。
  3. 在 Cursor 的 skills 目录中创建新文件夹。
  4. 将所有 skill 文件复制到新文件夹中。
  5. 重启 Cursor 让新的 skill 生效。

GitHub Copilot — Git Clone 安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 克隆仓库:git clone https://github.com/brycewang-stanford/Auto-Empirical-Research-Skills.git
  3. 将 "skills/17-DAAF-Contribution-Community-daaf/dot-claude/skills/election-data-source-countypres" 文件夹复制到 GitHub Copilot 的 skills 目录中。
  4. 重启 GitHub Copilot 让新的 skill 生效。

GitHub Copilot — 手动复制安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 从源仓库下载 SKILL.md 及相关文件。
  3. 在 GitHub Copilot 的 skills 目录中创建新文件夹。
  4. 将所有 skill 文件复制到新文件夹中。
  5. 重启 GitHub Copilot 让新的 skill 生效。

Windsurf — Git Clone 安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 克隆仓库:git clone https://github.com/brycewang-stanford/Auto-Empirical-Research-Skills.git
  3. 将 "skills/17-DAAF-Contribution-Community-daaf/dot-claude/skills/election-data-source-countypres" 文件夹复制到 Windsurf 的 skills 目录中。
  4. 重启 Windsurf 让新的 skill 生效。

Windsurf — 手动复制安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 从源仓库下载 SKILL.md 及相关文件。
  3. 在 Windsurf 的 skills 目录中创建新文件夹。
  4. 将所有 skill 文件复制到新文件夹中。
  5. 重启 Windsurf 让新的 skill 生效。
查看 SKILL.md 原文
name: election-data-source-countypres
description: >-
  County Presidential Returns 2000-2024 (MIT MEDSL). Vote shares, party trends, turnout by county_fips (joins census/education data). Requires HARVARD_DATAVERSE_API_KEY. Critical: mode='TOTAL' drops ~1K counties post-2020 — use 3-pattern reconstruction
metadata:
  audience: any-agent
  domain: data-source
  skill-authored: "2026-02-23"
  skill-last-updated: "2026-02-24"

County Presidential Data Source Reference

County Presidential Election Returns 2000-2024 from MIT Election Data and Science Lab (MEDSL). Use when analyzing county-level presidential vote shares, party trends, turnout, or geographic voting patterns. Key join column county_fips enables linking to census, education (CCD/SAIPE), and demographic datasets. Requires Harvard Dataverse API key (HARVARD_DATAVERSE_API_KEY env var). Categorical variables use uppercase strings, not Portal integer codes. Critical caveat: naive mode='TOTAL' filtering silently drops ~1,000 counties in 2020+ data — use 3-pattern reconstruction.

The authoritative source for county-level U.S. presidential election returns spanning 2000-2024. Provides candidate-level vote counts across all 50 states and DC, enabling vote share analysis, partisan trend mapping, and cross-domain geographic research via FIPS code joins.

CRITICAL: Value Encoding

This dataset uses uppercase string codes for categorical variables (party, mode, candidate, state) rather than integer codes. Empty strings ("") appear as undocumented values in party (501 rows, 2024) and mode (2,795 rows, 2024).

Contextpartymodecandidate
Standard valuesDEMOCRAT, REPUBLICANTOTALBARACK OBAMA
Aggregate/meta valuesOTHER, """", ELECTION DAYOTHER, UNDERVOTES

See ./references/variable-definitions.md for complete encoding tables.

Prerequisites

API Key Required: This data source requires a Harvard Dataverse API key to fetch data. Unlike education data sources (which use the Urban Institute's free, unauthenticated API), election data is hosted on Harvard Dataverse and requires authentication.

Setup instructions:

  1. Create a free Harvard Dataverse account at https://dataverse.harvard.edu/
  2. Log in, navigate to your account name (top-right) → API Token
  3. Click "Create Token" and copy it
  4. Set the environment variable before launching Claude Code:
    export HARVARD_DATAVERSE_API_KEY="your_token_here"
    
    For Docker users: run this inside the container after docker compose exec daaf-docker bash but before claude. To make it persistent across sessions, add it to ~/.bashrc.

If the key is missing, any fetch script will fail with a KeyError: 'HARVARD_DATAVERSE_API_KEY'. The orchestrator should check for this variable's existence before dispatching Stage 5 fetch tasks that use this data source.

What is the MEDSL County Presidential Returns Dataset?

  • Producer: MIT Election Data and Science Lab (MEDSL)
  • Coverage: County-level presidential election returns, 50 states + DC
  • Frequency: Every 4 years (presidential election cycle)
  • Available years: 2000, 2004, 2008, 2012, 2016, 2020, 2024
  • Primary identifier: county_fips (5-digit FIPS code, stored as integer)
  • Record unit: One row per county-year-candidate-party-mode combination
  • Total records: 94,151 rows x 12 columns (~8.4 MB). Note: rows per year vary dramatically — 2020/2024 have ~2x rows due to mode breakdowns (~22K vs ~9.5K for earlier years)
  • Source: Harvard Dataverse (DOI: 10.7910/DVN/VOQCHQ)

Reference File Structure

FilePurposeWhen to Read
variable-definitions.mdComplete column specs, party/mode/candidate value tablesInterpreting specific columns or coded values
coded-values.mdAll categorical value mappings with frequenciesFiltering or recoding party, mode, candidate
columns.mdDetailed per-column profiling (types, nulls, ranges)Understanding column characteristics
quality-notes.mdKnown issues, anomalies, duplicates, null patternsAssessing data reliability
mode-reconstruction.md3-pattern TOTAL mode reconstruction for 2020+ dataCleaning any 2020+ analysis (CRITICAL)
interpretations.mdPreliminary semantic interpretations (flagged for review)Understanding column meanings

Decision Trees

What analysis do I need?

Analyzing presidential election data?
├─ County-level vote shares → Use 3-pattern mode reconstruction (./references/mode-reconstruction.md)
│   └─ Longitudinal (cross-year) → MUST reconstruct TOTAL for 2020+ (naive filter drops ~1,000 counties)
│   └─ Single year (pre-2020) → Safe to filter mode='TOTAL'
│   └─ Single year (2020/2024) → Reconstruct unless analyzing a known TOTAL-only state
├─ Party trends → Group by year + party, use party column (not candidate name)
│   └─ Third parties → See ./references/coded-values.md (GREEN/LIBERTARIAN vary by year)
├─ Turnout analysis → Use totalvotes column (dedup per county-year before summing!)
├─ Joining with other data → Use county_fips as join key (zero-pad to 5 chars first!)
│   └─ Census/ACS data → Join on county_fips (standard 5-digit string)
│   └─ Education data (CCD/SAIPE) → Join on county_fips
│   └─ Null FIPS? → See ./references/quality-notes.md (CT, ME, RI)
└─ Voting method analysis → 2020 and 2024 only, see mode breakdown

Is this a data quality issue?

Unexpected values?
├─ county_fips is null → CT/ME/RI in pre-2020 years (52 rows)
├─ county_fips > 72999 → Kansas City MO (FIPS 2938000, non-standard)
├─ county_fips join failures → Zero-pad to 5 chars! (AR codes = 4 digits as int)
├─ AR FIPS 5135 has two counties → Source data error: St. Francis under Sharp County
│   └─ See ./references/quality-notes.md #arkansas-fips-contamination (BLOCKER)
├─ CT counties missing from shapefile → 2022+ TIGER uses planning regions, not counties
│   └─ See ./references/quality-notes.md #connecticut-fips-geography-mismatch
├─ ~1,000 counties missing after mode filter → Use 3-pattern reconstruction, not naive filter
│   └─ See ./references/mode-reconstruction.md
├─ candidate is not a person → UNDERVOTES/OVERVOTES/SPOILED/TOTAL VOTES CAST
│   └─ Filter these OUT for candidate-level analysis
├─ party is empty string → 501 rows in 2024, undocumented
├─ mode is empty string → 2,795 rows in 2024 (may be totals OR breakdowns per state)
├─ candidatevotes is null → 37 rows (NM 2024, mode breakdown)
├─ sum(candidatevotes) > totalvotes → 49 county-years (minor rounding)
├─ Duplicate rows → 83 exact duplicates exist
└─ Alaska 2004 → District-level data, not county; FIPS = 2001-2099
    └─ See ./references/quality-notes.md #alaska-2004

Quick Reference: Election Variables

Party Values by Year

YearDEMOCRATREPUBLICANLIBERTARIANGREENOTHER""
2000YY-YY-
2004-2016YY--Y-
2020YYYYY-
2024YYY-YY

Mode Values by Year

YearModes Available
2000-2016TOTAL only
2020TOTAL + 15 breakdown modes (11 states)
2024TOTAL + 9 breakdown modes + "" (varies by state)

For complete mode values see ./references/coded-values.md.

Key Identifiers

IDFormatLevelExampleNotes
county_fipsInt64 (5-digit)County6037 (LA County, CA)52 nulls (CT/ME/RI); join key for census/education data
state_poString (2-char)StateCAUSPS abbreviation; 1:1 with state
stateStringStateCALIFORNIAFull uppercase name

WARNING: FIPS Zero-Padding Required for Joins

county_fips is stored as Int64. When converting to string for joins with Census, SAIPE, CCD, or other datasets, zero-pad to 5 characters or Arkansas and other small-FIPS states will produce 4-digit codes that fail to match.

df = df.with_columns(pl.col("county_fips").cast(pl.Utf8).str.zfill(5).alias("county_fips_str"))

Missing Data Codes

CodeColumn(s)MeaningFrequency
nullcounty_fipsFIPS not assigned52 rows (CT, ME, RI pre-2020)
nullcandidatevotesVote count unavailable37 rows (NM 2024 mode breakdowns)
0totalvotesNo votes recorded50 rows
0candidatevotesZero votes for candidate3,908 rows (4.15%)
""partyParty not specified501 rows (2024 only)
""modeMode not specified2,795 rows (2024 only)

Non-Candidate Entries in candidate Column

ValueRowsMeaning
OTHER27,548Aggregate of minor candidates
TOTAL VOTES CAST427County total (redundant with totalvotes)
UNDERVOTES402Ballots with no presidential selection
OVERVOTES380Ballots with multiple presidential selections
SPOILED14Invalidated ballots

Filter these out for candidate-level vote share analysis.

Best Practice: Party-Based Identification

Always use party column for identifying party affiliation, never candidate name. Candidate names are inconsistent across years (e.g., "DONALD TRUMP" in 2016 vs "DONALD J TRUMP" in 2020/2024). The party column (DEMOCRAT, REPUBLICAN) is stable across all years.

# CORRECT — stable across years
dem = df.filter(pl.col("party") == "DEMOCRAT")

# WRONG — misses 2016 or 2020/2024 depending on which name you use
trump = df.filter(pl.col("candidate") == "DONALD TRUMP")

Data Access

Dataset Paths

TopicTypePath
County presidential returnsSingle fileHarvard Dataverse DOI: 10.7910/DVN/VOQCHQ
CodebookSingle fileBundled: County Presidential Returns 2000-2024.md
Sources per stateSingle fileBundled: sources-president.tab

Codebooks

DatasetCodebook Path
County presidential returns 2000-2024County Presidential Returns 2000-2024.md (bundled in Dataverse)

Codebook is a Markdown file bundled in the Harvard Dataverse deposit. For human reference. The QA methodology paper is at: https://www.nature.com/articles/s41597-022-01745-0

Truth Hierarchy: When interpreting variable values, apply this priority:

  1. Actual data file (what you observe in the TSV) -- this IS the truth
  2. Live codebook (Markdown file in Dataverse) -- authoritative documentation, may lag
  3. This skill documentation -- convenient summary, may drift from codebook

If this documentation contradicts the codebook, trust the codebook. If the codebook contradicts observed data, trust the data and investigate.

Example Fetch

# Fetch from Harvard Dataverse API
import os, requests, polars as pl, io

api_key = os.environ["HARVARD_DATAVERSE_API_KEY"]
# Get file ID from dataset metadata first, then download
# File: countypres_2000-2024.tab (TSV format)
file_url = "https://dataverse.harvard.edu/api/access/datafile/{file_id}"
r = requests.get(file_url, params={"key": api_key, "format": "original"})
df = pl.read_csv(io.BytesIO(r.content), separator='\t')

# Filter to California, 2020, TOTAL mode only
ca_2020 = df.filter(
    (pl.col("state_po") == "CA") &
    (pl.col("year") == 2020) &
    (pl.col("mode") == "TOTAL")
)

Filtering

# Common filter patterns for county presidential data

# 1. Cross-year analysis: WARNING — naive filter drops ~1,000 counties in 2020+!
#    Use 3-pattern mode reconstruction instead. See ./references/mode-reconstruction.md
#    The single-line filter below is ONLY safe for single-year analysis on a state
#    known to have TOTAL rows (e.g., 2000-2016 data, or a confirmed TOTAL-only state).
longitudinal = df.filter(pl.col("mode") == "TOTAL")  # UNSAFE for 2020+ multi-state!

# 2. Remove non-candidate rows (UNDERVOTES, OVERVOTES, etc.)
candidates_only = df.filter(
    ~pl.col("candidate").is_in(["TOTAL VOTES CAST", "UNDERVOTES", "OVERVOTES", "SPOILED"])
)

# 3. Major party analysis — RECOMMENDED: use party column, not candidate name
#    Candidate names change across years (e.g., "DONALD TRUMP" vs "DONALD J TRUMP")
two_party = df.filter(pl.col("party").is_in(["DEMOCRAT", "REPUBLICAN"]))

# 4. Exclude Alaska 2004 anomaly
clean = df.filter(~((pl.col("state_po") == "AK") & (pl.col("year") == 2004)))

# 5. Exclude rows with null county_fips (for join operations)
joinable = df.filter(pl.col("county_fips").is_not_null())

Common Pitfalls

PitfallIssueSolution
Cross-year mode mismatch2000-2016 has only TOTAL; 2020/2024 have breakdowns. Mixing modes inflates countsAlways filter mode == 'TOTAL' for longitudinal analysis
Non-candidate rowsUNDERVOTES, OVERVOTES, SPOILED, TOTAL VOTES CAST appear as "candidates"Filter out before computing candidate vote shares
Alaska 2004District-level data with non-standard FIPS codes (2001-2099); vote counts overstatedExclude AK 2004 or handle separately; do not join on county_fips
Null FIPS for joinsCT, ME, RI have null county_fips in some years; breaks joinsUse state_po + county_name as fallback join key
Kansas City MO FIPSUses non-standard FIPS 2938000 (not a real county FIPS)Handle as special case in joins; Kansas City is an independent city
Empty string party/mode2024 has "" in party (501 rows) and mode (2,795 rows)Treat as missing/undocumented; filter or investigate by state
Vote share > 100%49 county-years where sum(candidatevotes) > totalvotesMinor rounding; use caution with strict validation
Duplicate rows83 exact duplicate rows exist in datasetDeduplicate before analysis
FIPS zero-paddingInt64 → string without padding gives 4-digit codes for AR and other small-FIPS statespl.col("county_fips").cast(pl.Utf8).str.zfill(5) before joins
Name-based party IDCandidate names change across years ("DONALD TRUMP" vs "DONALD J TRUMP")Always use party column, never candidate name
CT FIPS mismatch2022+ Census TIGER uses CT planning regions, not legacy countiesUse 2020-vintage TIGER shapefiles for CT county joins
totalvotes duplicationtotalvotes is repeated per candidate row; summing without dedup inflates by ~3-4xDeduplicate to one row per (county_fips, year) before aggregating

Critical: Mode Column Behavior Change

WARNING: Naive mode == "TOTAL" filtering drops ~1,000 counties in 2020+ data. Multiple states report ONLY mode breakdowns (no TOTAL rows). A simple filter silently removes all their counties. Use 3-pattern mode reconstruction instead. See ./references/mode-reconstruction.md for the full code pattern and validation.

The mode column behavior changed significantly starting in 2020:

  • 2000-2016: All rows have mode = 'TOTAL' (aggregate county totals only)
  • 2020: 11 states report by voting method alongside TOTAL; 10 states have ONLY breakdowns (AR, AZ, GA, IA, KY, MD, NC, OK, SC, VA)
  • 2024: Additional breakdown states; some have empty string mode (which may represent totals OR breakdowns depending on the state)

For any cross-year or multi-county analysis, use 3-pattern mode reconstruction:

  1. Pattern 1: TOTAL present → keep TOTAL, drop breakdowns
  2. Pattern 2: Only breakdowns, no TOTAL → sum candidatevotes across modes
  3. Pattern 3: Empty-string mode = totals → reclassify after per-state verification

Empty-string detection must be per-state — NC 2024 empty-string rows are breakdowns (multiple per county-candidate), while other states' empty-string rows are totals (one per county-candidate). See ./references/mode-reconstruction.md for detection logic and code.

Related Data Sources

SourceRelationshipWhen to Use
Census/ACSJoin via county_fipsCounty demographics, population, income
SAIPE (education-data-source-saipe)Join via county_fipsCounty poverty estimates (cross-domain)
CCD (education-data-source-ccd)Join via county_fipsSchool district data (cross-domain)
MEDSL Precinct ReturnsFiner geographic resolutionWhen county-level is insufficient
MEDSL Senate/House ReturnsSame producer, different officeWhen analyzing down-ballot races

Note: This is the first election domain dataset in DAAF. Cross-domain joins with education data are possible via county_fips. No election-specific explorer or query skills exist yet.

Topic Index

TopicReference File
Column specifications./references/columns.md
Column types and ranges./references/columns.md
Party values and year coverage./references/coded-values.md
Mode values and year behavior./references/coded-values.md
Candidate name mapping./references/coded-values.md
Non-candidate entries./references/coded-values.md
Complete encoding tables./references/variable-definitions.md
Null county_fips patterns./references/quality-notes.md
Alaska 2004 anomaly./references/quality-notes.md
Kansas City MO FIPS./references/quality-notes.md
Duplicate rows./references/quality-notes.md
Null candidatevotes./references/quality-notes.md
Per-state data sources./references/quality-notes.md
Missing votes flags./references/quality-notes.md
Mode reconstruction (3-pattern)./references/mode-reconstruction.md
States without TOTAL rows./references/mode-reconstruction.md
Empty-string mode detection./references/mode-reconstruction.md
Row count estimation by year./references/mode-reconstruction.md
FIPS zero-padding for joins./references/columns.md
AR FIPS contamination (Sharp/St. Francis)./references/quality-notes.md
CT geography mismatch (2022+)./references/quality-notes.md
Party-based identification (best practice)./references/coded-values.md
totalvotes deduplication./references/variable-definitions.md
Preliminary interpretations./references/interpretations.md
Data profiling scripts./scripts/

发现问题?提交给管理员复核

评分:

评论 (0)

暂无评论,成为第一个评论者吧!