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

Exit Codes

stacy uses consistent exit codes to indicate success or failure type.

Exit Code Table

CodeNameDescription
0SuccessOperation completed successfully
1Stata ErrorStata r() code detected in log
2Syntax ErrorInvalid Stata syntax
3File ErrorFile not found, permission denied, data errors
4Memory ErrorInsufficient memory
5Internal Errorstacy itself failed (not Stata)
6Statistical ErrorConvergence failure, model problems
10Environment ErrorStata not found or configuration invalid

Stata r() Code Mapping

The number inside r(N) is preserved in stacy’s output (JSON field r_code, stored result r(exit_code) in Stata). The shell exit code is a category derived from it, in two steps:

  1. Error database lookup. stacy extracts error descriptions and categories from your local Stata installation (run stacy doctor --refresh after a Stata upgrade). If the code is found there, its category decides the exit code.
  2. Range fallback. Otherwise, the documented ranges from Stata’s Programming Reference Manual apply:
Exit CodeStata r() Codes
1all r() codes not in other categories
2r(100)-r(199), e.g. r(198), r(199)
3r(600)-r(699), e.g. r(601), r(603)
4r(900)-r(999), e.g. r(950)
6r(400)-r(499)
10r(800)-r(899)

Usage

Shell

stacy run analysis.do
echo $?  # 0 on success, 1-10 on failure

Makefile

results.dta: analysis.do
	stacy run analysis.do  # Stops on non-zero exit

This mapping is many-to-one by design: it compresses Stata’s hundreds of return codes into a small, stable set that build tools can branch on.

Stability

Exit codes 0-10 are stable and will not change meaning. New categories may be added with codes 11+.

See Also