Claude Code for applied economists: data, Stata or R, and a replication package

Publicado em 2026-10-12

Most weeks of empirical work look the same: download a few series, merge them with a messy administrative file, write and rerun do-files, try an event study, add robustness checks, and, at the end, assemble a replication package the journal's data editor can run. A chat window can draft code for each step, but you still copy it back and forth. A coding agent such as Claude Code works inside your project folder instead: it reads your files, writes and runs scripts, sees the errors and fixes them.

Economists took to this early. In Anthropic's survey of 1,260 quantitative social scientists (fielded late February and March 2026, published May 27, 2026), 39% of the economists who responded used a coding agent more than once a week, against 20% of all respondents. The sample was not representative: respondents were recruited for a study that offered Claude Max accounts, so it likely leans toward researchers already curious about AI tools. Paul Goldsmith-Pinkham's eight-episode series for Princeton BCF (March 29 to July 3, 2026) walks through Census data, scraping SEC EDGAR filings into DuckDB, and very large CSVs.

Before you start

  • An account. Claude Code needs a Pro, Max, Team, Enterprise or Console account; the free Claude.ai plan does not include it. It can also run through Amazon Bedrock, Google Cloud's Agent Platform or Microsoft Foundry, which may suit a university cloud agreement (setup docs).
  • A terminal. Commands in the bash blocks below go in a terminal (Terminal on macOS, PowerShell on Windows), not at the Claude Code prompt; Anthropic's terminal guide covers the basics. The plain-text blocks are example prompts to type into Claude Code. After you add an MCP server, restart Claude Code so it sees the new tools.
  • Node.js or uv for some tools. Several tools install with npx, which comes with Node.js, or run with uvx, which comes with uv.
  • Git. Keep each project in a git repository, so every change the agent makes can be reviewed and undone, and have the agent do each piece of analysis on its own branch rather than directly on main (Step 3 shows why).
  • A CLAUDE.md file. Put a short CLAUDE.md in the project root saying what the project is, where the data come from, which sample restrictions are intended, and that raw data are never overwritten. Claude Code reads it at the start of every session.

If you are starting a new project rather than adding an agent to an existing one, you can also fork My Claude Code Setup, a complete research template described in Step 4.

Where to start

Your situationStart withWhat you need first
You work in StataStata MCPLicensed Stata 17+; VS Code, Cursor or Antigravity
You work in Rmcptools, plus Posit's btw packageR; btw for the doc and object tools
You need FRED seriesFRED MCP ServerFRED API key, Node.js
You need firm filingsEdgarToolsuv, your name and email
You need BEA, BLS, Census or World Bank dataDatabase LookupNode.js; an API key for BEA
Files too big for memoryDuckDBHomebrew or the official installer
Identification and estimationAuto-Empirical Research Skills (AERS)Claude Code v2.1+; Stata for the Stata pipeline
Auditing your analysis codeAI Research FeedbackNode.js, a git repository
Starting a new projectMy Claude Code Setup (claude-code-my-workflow)GitHub account, Git, Python 3
SubmissionQuarto, Econ Writing SkillQuarto (plus TeX for PDF); Node.js

Step 1: Connect the agent to Stata or R

Stata MCPMCPLets Claude Code run your do-files in a real Stata session and read the output.hanlulong/stata-mcp511

Stata MCP is an extension for VS Code, Cursor or Antigravity (Google's code editor) that starts a local MCP server; an MCP server is a plug-in that gives the agent new tools. It needs a licensed Stata 17 or later, and the editor must be open with the extension running; the status bar then shows Stata. The catalog command installs the extension in VS Code and registers the server with Claude Code:

code --install-extension DeepEcon.stata-mcp && claude mcp add --transport http --scope user stata-mcp http://localhost:4000/mcp-streamable

The code command works only if VS Code has put it on your PATH (on a Mac, run Shell Command: Install 'code' command in PATH from VS Code's Command Palette). You can instead open the editor's Extensions view, search for Stata MCP, install it there, and then run only the claude mcp add part. Cursor users can run cursor --install-extension DeepEcon.stata-mcp. Restart Claude Code afterwards.

One setting matters for economists: by default the extension returns output in compact mode, which filters messages like (N real changes made) and (N missing values generated) to save tokens. Those are the lines that reveal silent data changes, so set stata-vscode.resultDisplayMode to full in the editor settings while you clean data. Each parallel session takes about 200 to 300 MB of RAM, and your Stata license may limit concurrent instances. Without one of these editors, Claude Code can still run do-files in Stata's batch mode from the terminal and read the .log file Stata writes, but you lose the live session and the extension's tools.

Read CLAUDE.md and the do-files in code/. Using the Stata tools, run code/01_clean.do
on the data in data/raw (never write to that folder). After every merge, keep, drop
and reshape, log the observation count and the merge result table. Then list every
place where observations were lost, why, and how many.
mcptoolsMCPPosit's bridge between Claude Code and the R sessions you already have open.posit-dev/mcptools202

Claude Code can already run Rscript in a terminal. mcptools connects it to the R sessions you have open, with their data in memory, but on its own its server only lists those sessions and switches between them. Install the package in R with install.packages("mcptools"), then register it:

claude mcp add -s "user" r-mcptools -- Rscript -e "mcptools::mcp_server()"

Run mcptools::mcp_session() in each R session you want the agent to see; the README suggests putting that call in your .Rprofile so every session registers itself. The package is marked experimental.

The tools that let the agent read the documentation of your installed packages and inspect the objects in your environment come from Posit's btw package, which builds on mcptools and is not in this catalog. Install it with install.packages("btw") and register its server with the tool groups from the btw MCP documentation:

claude mcp add -s "user" r-btw -- Rscript -e "btw::btw_mcp_server(list('docs', 'pkg', 'env', 'sessioninfo', 'cran'))"

Then call btw::btw_mcp_session() in each R session the agent should see.

Read CLAUDE.md and the scripts in code/. Run code/01_clean.R on the data in data/raw
(never write to that folder). Log nrow() after every join, filter and pivot, and
count unmatched rows for every join. Then list every place where rows were lost,
why, and how many.

Step 2: Get the data, with a script that rebuilds it

Use the data tools below to find and check what you need: series IDs, units, which filing facts hold your variables. Then have the agent write a script that does the actual download. Whatever an MCP tool returns passes through the model's context: a long monthly series or hundreds of firms copied from there into a CSV fills the context and can pick up transcription errors. A script saves exactly what the source returned, and anyone, including the data editor, can rerun it.

FRED MCP ServerMCPSearch FRED series and check units and dates, with year-over-year and other transformations built in.stefanoamorelli/fred-mcp-server125

FRED MCP Server gives the agent three tools: browse the catalog, search series, and fetch a series by ID with date ranges, units (for example percent change from a year ago, or logs) and frequency aggregation. It needs a FRED API key, which you request after logging in to a FRED account, and Node.js:

claude mcp add -e FRED_API_KEY=YOUR_FRED_API_KEY fred -- npx -y fred-mcp-server

It is a community project, not affiliated with the St. Louis Fed. FRED serves the latest revised data; if your design depends on what was known at the time, use the vintages in ALFRED and record download dates. The download script can use the same key; keep it out of the script itself, for example in a FRED_API_KEY environment variable set before you start Claude Code.

EdgarToolsMCP10-K, 10-Q and 8-K filings, XBRL financial statements, Form 4 and 13F, no API key.dgunning/edgartools2.8k

EdgarTools is a Python library with a built-in MCP server for SEC filings. It reads XBRL (the machine-readable tags on the financial statements in filings), Form 4 insider trades and 13F institutional holdings. It needs no key, but you identify yourself with your name and email, and the MCP server runs through uv:

claude mcp add -e EDGAR_IDENTITY="Your Name your.email@example.com" edgartools -- uvx --from "edgartools[ai]" edgartools-mcp

The SEC caps automated access at 10 requests per second and asks for a declared user agent, so large pulls take time. The standardized statements help cross-firm comparison, but check how your key variables map to the original filing before you rely on them. For the download script, the agent can call the library directly (pip install edgartools, then set_identity with your email, per the README).

Database LookupSkillTraceable queries to FRED, BEA, BLS, Census, World Bank and EDGAR APIs, with endpoints and dates recorded.K-Dense-AI/scientific-agent-skills48.5k

Database Lookup is a skill from K-Dense's scientific collection that queries about 80 public database APIs. Most are scientific (PubChem, UniProt), but its list includes FRED, BEA, BLS, the US Census, the World Bank, Eurostat and SEC EDGAR, so name the source in your prompt. It tells the agent to record the endpoint, parameters and access date of every query, which is what you need to turn a lookup into a download script. BEA needs an API key; BLS and the Census work without one up to a limit (25 requests a day for BLS's basic API). Install it with Node.js:

npx skills add K-Dense-AI/scientific-agent-skills --skill database-lookup -a claude-code -y
Use the FRED tools to find monthly UNRATE and CPIAUCSL and confirm their units, and
use the EdgarTools tools to check which 10-K facts hold total assets and revenue for
two CIKs from data/raw/cik_list.csv. Do not copy data from tool output into files.
Write code/get_data.py that downloads both series from 2000-01 to the latest
observation (CPI as percent change from a year ago, API key read from the
FRED_API_KEY environment variable) and those 10-K facts for every CIK in the list
with the edgartools library. Save each raw pull to data/raw/ with the download date
in the file name, run the script, and list series IDs and sources in data/SOURCES.md.
DuckDBCLIQuery large CSV and Parquet files with SQL, with no import step or database server.duckdb/duckdb42.2k

When a file is too large to open in Stata or R, ask the agent to convert it to Parquet (a compressed, column-based file format) and query it with DuckDB, the approach in episode 4 of the Goldsmith-Pinkham series. On a Mac with Homebrew:

brew install duckdb

Other systems: see the installation page at duckdb.org.

Step 3: Identification and robustness checks

This is where the agent saves the most typing and needs the most supervision. Ask it to state the design and its assumptions before it estimates anything.

Auto-Empirical Research Skills (AERS)SkillEstimation pipelines for DiD, RD and IV designs in Stata, R or Python; install one plugin at a time.brycewang-stanford/Auto-Empirical-Research-Skills4.6k

Auto-Empirical Research Skills (AERS), from Stanford REAP and CoPaper.AI, bundles 77 skill collections covering topic choice through writing, including difference-in-differences (DiD), regression discontinuity (RD) and instrumental variables (IV) designs. Install only the pipeline you need from its plugin marketplace, which the README says needs Claude Code v2.1 or later:

claude plugin marketplace add brycewang-stanford/Auto-Empirical-Research-Skills
claude plugin install empirical-analysis-stata@auto-empirical-research-skills

For R, install empirical-analysis-r@auto-empirical-research-skills instead; there is also empirical-analysis-python@auto-empirical-research-skills. The Stata pipeline uses reghdfe, ivreg2, csdid, sdid and rdrobust and needs Stata installed; the R pipeline uses fixest, did and HonestDiD and renders its results with Quarto.

The catalog's one-line command for AERS uses --skill '*'. Avoid it: it installs all 1,107 skills in the repository, including copies of AI Research Feedback, Econ Writing Skill and My Claude Code Setup that would duplicate the installs in this guide, and de-AIGC skills meant to get text past AI detectors such as Turnitin and GPTZero and to strip watermarks. Do not use those; disclose AI use instead. Most collections in the repository are snapshots of third-party projects with their own licenses.

AI Research FeedbackSkillEconomist Claes Bäckman's review skills, including an adversarial audit of analysis code.claesbackman/AI-research-feedback497
npx skills add claesbackman/AI-research-feedback --skill '*' -a claude-code -y

The skill to know is /audit-analysis. It hands your code changes to a subagent with a clean context and tells it to break them: sample sizes before and after every filter, merge and collapse; merge keys and unmatched observations; missings coerced to zero; clustering and what fixed effects absorb. Every finding must cite a file and line, and the audit changes nothing in your repository. It compares your work with a base, which is main unless you name another branch, tag or commit. So have the agent work on a new branch, as in the prompt below, and run /audit-analysis from that branch. If your default branch is called master, or the work is already committed to main, pass the base yourself: /audit-analysis master, or /audit-analysis abc123, where abc123 is the commit from before the analysis. Otherwise there is no difference to audit.

/review-paper-code maps the main empirical claims in your LaTeX paper to the code that should produce them. These review skills run only when you type the command, and most expect a LaTeX manuscript.

data/clean/panel.dta is a state-year panel with staggered adoption (adopt_year).
Before changing anything, create a new git branch called did-event-study and commit
there. Write down the identification strategy and its assumptions before estimating.
Then estimate a Callaway-Sant'Anna event study and a TWFE comparison in R, cluster
by state, and add a pre-trend sensitivity check. Do not change the sample to improve
results; if a check fails, report it.

TWFE is the two-way fixed effects regression; setting it beside the Callaway-Sant'Anna estimates shows how much the staggered timing matters. Then run /audit-analysis on that branch and read every finding yourself.

Step 4: Build the replication package

The AEA's Data and Code Availability Policy (February 2026 version) asks for the data with a Data Availability Statement explaining how others can access them, all code, and a README in PDF format with software requirements, expected running time and step-by-step instructions. It strongly encourages depositing in the AEA Data and Code Repository at openICPSR, though other trusted repositories may be acceptable, and the Data Editor runs reproducibility checks. The Social Science Data Editors' template README is not required but strongly encouraged.

My Claude Code Setup (claude-code-my-workflow)SkillPedro Sant'Anna's forkable research template, with replication-package and reproducibility commands.pedrohcgs/claude-code-my-workflow1.7k

My Claude Code Setup (claude-code-my-workflow) is econometrician Pedro Sant'Anna's whole project template rather than a single skill: you fork it when you start a project, and its README describes it as a hub for an entire research program. At submission, /replication-package assembles an openICPSR-style package with a README, dataset manifest, computational requirements and a map from each table and figure to the script line that produces it; /capture-environment records the software environment (renv.lock for R, requirements files for Python, the Stata version and ado list); and /audit-reproducibility cross-checks numbers in the manuscript against script output. Its analysis commands are R-first, with /stata-replication driving Stata through Stata MCP. It needs Claude Code, Git and Python 3. There is no one-line install: fork the repository on GitHub, then, per the README:

git clone https://github.com/YOUR_USERNAME/claude-code-my-workflow.git my-project
cd my-project
./scripts/validate-setup.sh

If your paper already lives in its own repository, you do not need to move it: use Econ Writing Skill and the prompt at the end of this step for the package, and consider the template for your next project. Check its permission file before you use it with sensitive data: the template's .claude/settings.json ships broad allow rules such as Bash(*), Edit(**) and Write(**), and its README tells you to add deny rules for restricted data.

QuartoCLIRenders Markdown with R, Python or Julia code into HTML, PDF or Word: READMEs, appendices, reports.quarto-dev/quarto-cli6.1k

Quarto turns a Markdown file, optionally with R, Python or Julia code in it, into HTML, PDF or Word. In a replication package it does two jobs: it renders the README you write in Markdown to the PDF the AEA asks for, and it renders a results appendix straight from code, so every number in it is recomputed each time. The AERS R pipeline from Step 3 already uses it. There is no agent plugin; the agent simply runs quarto render. Download the installer from quarto.org; PDF output also needs a TeX distribution, which quarto install tinytex sets up (PDF basics). Its README lists Python, R, Julia and JavaScript as the languages it runs, so Stata users keep their do-files and bring in the tables and logs those write.

Econ Writing SkillSkillEconomics writing rules, AEA replication standards and AI-disclosure guidance in one skill.hanlulong/econ-writing-skill664
npx skills add hanlulong/econ-writing-skill --skill econ-write -a claude-code -y

Econ Writing Skill is mainly a writing skill: it structures abstracts, introductions and conclusions by paper type and identification strategy, and simulates referee scores. Here it matters for its section on AEA Data Editor standards (README structure, data citation, code reproducibility), its notes on journal policies for disclosing AI assistance, and its flags on citations to verify. That section is guidance, not a checker. Its README asks you to use only one installation method.

Prepare a replication package following the AEA Data and Code Availability Policy
and the Social Science Data Editors' template README. Write a master script that
runs everything from raw data in order, record software and package versions,
estimate running time, and map every table and figure in paper/main.tex to the
script and line that produces it. Flag data we cannot redistribute and draft the
Data Availability Statement for me to edit.

Limits and risks

  • AI help has not beaten careful human checking. In a randomized study of 288 researchers in 103 teams (Brodeur et al., PNAS, May 2026), human-only teams reproduced 94% of published results, AI-assisted teams 91% and AI-led teams 37%. Human-only teams also found significantly more major coding errors than AI-assisted ones. The study used ChatGPT, not a coding agent, and the authors call the AI-led result likely only a lower bound on AI capabilities. Still, keep a person in charge of every check.
  • Rows disappear silently. Merges, filters and type conversions can drop or alter observations without an error. Require logged counts at every step, use assert in Stata, and read the merge tables yourself.
  • References can be invented. Check every citation against the published paper before it enters your bibliography.
  • Restricted data. Claude Code runs on your machine, but prompts and model outputs travel over the network to the model, and that includes whatever Stata or R prints back to it (a list, a describe, a merge table). On Pro and Max accounts your data can be used for training if that setting is on; under commercial terms (Team, Enterprise, API and cloud providers) Anthropic does not train on Claude Code prompts unless the organization has chosen to share data for model improvement (data usage). A Read(./data/restricted/**) deny rule blocks Claude's file tools and commands like cat, but not a script that opens the file itself, which is exactly what a do-file does; blocking every process takes the sandbox, which native Windows does not support (permissions). If your data use agreement forbids sharing with third parties, do not point an agent at that data.
  • Disclosure and responsibility. Check your target journal's policy on AI use and disclose it. These tools assist; a qualified researcher must review every estimate, table and sentence that goes out under their name.

Related collections

Applied economics with coding agentsFor economics PhD students, applied microeconomists and policy analysts: set up a project, get FRED and SEC data, run Stata, R or Python, draft and revise. Agents assist; check every merge, estimate and sentence. Local tools still send what the agent reads to the AI provider: check data agreements.14 recursos
Literature review to journal submissionFor grad students and postdocs in any field: search, screen and read, draft, fit a journal, check claims, tidy references, review and revise. Some steps need keys or sign-ins. Tools assist; you verify every citation and claim, follow the journal's AI policy and keep unpublished data private.15 recursos
Versão em Markdown (para agentes)