Tutorial / 4 min read

How to Create a Stata Skill in Claude Code

Set up Claude Code for Stata by putting Stata on PATH, creating a reusable Stata skill, and handling PDF docs efficiently with pandoc, pdfgrep, and pdfplumber.

The AI Economist
Watch the tutorial

How I've taught a dozen econ PhDs to use Claude Code with Stata

I've done 1 on 1 Claude Code training sessions with a dozen economists, almost all of whom use Stata.

Using Claude Code effectively with Stata requires a few setup steps not needed with more common language like Python/Typescript In this article, I'll teach you how to use Claude Code effectively with Stata.

Preliminary Notes

  • What I’m showing can be applied to any statistical package like SAS or SPSS.
  • I’ve also made a video version of this article: https://youtu.be/YLQvQ2MD2Y8
  • I dislike Stata and don’t use it. Python has become quite mature and effective for econometrics. But most economists are locked into Stata, and I want to meet them where they are.
  • If you use Windows, set up Claude Code with WSL first. I have a setup video here: How to Install Claude Code on Windows (WSL)

What We Need To Do

To use Stata effectively with Claude Code, there are three prerequisites:

  1. Put Stata on your terminal PATH
  2. Create a reusable Stata skill
  3. Handle PDF docs efficiently so you don’t burn tokens

Step 1: Put Stata on PATH

Most academics use Stata with the GUI, but Claude Code needs command-line access to Stata.

No bueno for Claude Code

This means your terminal must be configured so typing stata points to your Stata executable.

Ask Claude Code:

I want to put Stata onto my bashrc or zshrc, whichever is most relevant for me. Look through my file system, find the most recent Stata version, and get it onto my bashrc/zshrc.

Once you give that command, Claude should:

  1. Search your machine for the most recent Stata version
  2. Find the executable path
  3. Add that path to your PATH variable in .zshrc or .bashrc

.zshrc is the configuration file for macOS shells, and .bashrc is the configuration file for Linux and WSL.

Then verify in a new terminal session that Stata runs from the CLI.

Step 2: Create a Stata Skill

Claude Code may be aware of Stata without a distinct skill, but you’ll get better and more reliable usage if you create a dedicated Stata skill.

If you’re unfamiliar with skills in general, start with:

What should Claude Code know in your Stata skill?

  1. How to invoke Stata on your machine
  2. Where the Stata docs live on your machine
  3. Any preferences you have for writing Stata code

To create the skill, first install a Skill Creator skill. Two options:

  1. Anthropic skill creator from the main marketplace: SKILL.md Marketplace
  2. Skill Creator included in the Compound Engineering plugin: Compound Engineering plugin

I recommend option 2, since it also gives you the Compound Engineering plugin, which I’ve covered here: A Practitioner's Guide to Compound Engineering

Then, with Skill Creator installed, give Claude Code a prompt like this:

I want you to make me a skill scoped at the user level for working with Stata. I want you to include context on what Stata is and how to run and create do-files in my environment. I also want you to look up the location of this data documentation which is included in my installation.

What you'll get out at the end

It will be created in ~/.claude/skills and available in new Claude Code sessions.

Step 3: Solve the PDF Docs Problem

Stata docs are large PDFs, which are expensive for LLM context.

Ughhh

There are three approaches:

  1. Ignore it and accept high token cost
  2. Preprocess PDFs into markdown/text
  3. Give Claude tools to query PDFs efficiently

Option 2 is usually best long run, but for beginners I recommend option 3.

Tools I recommend installing:

Then tell Claude Code:

The stata skill currently references our stata documentation, which is a bunch of PDFs which are very token heavy to read. I want you to update the skill to include instructions as you see fit to use some combination of pandoc, pdfgrep, and pdfplumber to work with the documentation more efficiently.

Skills always need tweaking for your own workflow. With Skill Creator installed, Claude Code can usually do that tweaking effectively without much additional instruction.

If you have specific docs or best practices you want embedded in the skill, tell Claude Code and keep iterating.

Get the The AI Economist newsletter

How PhD economists are accelerating research with agentic tools, plus cutting-edge breakdowns of AI economics research