Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Introduction

Version License GitHub

stacy is a modern workflow tool for Stata. It runs scripts with proper exit codes, manages packages with lockfiles, and integrates Stata into reproducible pipelines.

For those familiar with other ecosystems:

If you know…stacy is like…Key similarity
RustCargoManifest + lockfile + build orchestration
Pythonuv or PoetryProject dependencies + reproducible environments
JavaScriptnpmpackage.json / package-lock.json workflow
RrenvProject-local library snapshots
Stata(nothing existed)This is what stacy provides

The Problem

Stata’s defaults leave two critical things implicit:

Dependencies are global and unversioned. Packages install to a global path. Versions are whatever SSC has today. When a package updates, every project using it changes silently. A replication package that worked six months ago may fail today because reghdfe changed its defaults.

Execution always returns success. Stata’s batch mode (stata-mp -b do script.do) exits with code 0 even when scripts fail. Errors are buried in logs. Build systems, CI pipelines, and orchestration tools cannot detect failure–they proceed as if nothing went wrong.

The Solution

stacy makes both sides explicit:

# Execution: proper exit codes
stacy run analysis.do
echo $?  # 0 on success, 1-10 on various errors

# Environment: lockfile-based packages
stacy add estout reghdfe    # Adds to stacy.toml, creates stacy.lock
stacy install               # Installs exact versions from lockfile

Now your builds stop on errors and your environments reproduce:

results/output.dta: analysis.do data/input.dta
    stacy run analysis.do   # Stops on failure

Before and After

Without stacyWith stacy
stata -b do script.do returns 0 even on errorstacy run script.do returns 1-10 on error
Packages are global, unversionedstacy.lock pins exact versions
Errors buried in log filesErrors displayed with documentation links
“It worked on my machine”Same versions everywhere via lockfile
Manual ssc install in scriptsstacy install from lockfile

Key Features

FeatureWhat it provides
Proper exit codesMaps 182 official Stata error codes to Unix exit codes
Lockfile managementstacy.lock pins exact versions with SHA256 checksums
Global package cachePackages cached at ~/.cache/stacy/packages/, shared across projects
Build system integrationWorks with Make, Snakemake, CI/CD
Single binaryNo runtime dependencies, easy to deploy

Note: Error detection uses 182 official Stata error codes from the Stata Programming Reference Manual–not heuristics.

Incremental Adoption

Even minimal usage restores critical functionality:

LevelWhat you doWhat you getWho this is for
1stacy run script.doExit codes workAnyone using Make/CI
2stacy initProject configurationTeams wanting standards
3stacy add pkgLocked dependenciesReproducibility needs
4Add [scripts]Task automationComplex workflows
5Integrate with Make/CIFull pipelinePublication-ready research

Quick Example

# Run with error detection
stacy run analysis.do

# Initialize a project and add packages
stacy init
stacy add estout reghdfe

# Install all packages from lockfile (like npm install)
stacy install

# Check system configuration
stacy doctor

How to Use These Docs

Next Steps