What is the DO file format?
A .do file is a plain-text script for Stata, the statistical software package developed by StataCorp. It holds a sequence of Stata commands - one per line - that execute in order when the script is run. Do-files are the standard way to write reproducible statistical analyses: instead of typing commands one at a time in the interactive console, researchers collect them in a .do file and run the whole sequence with the do or run command.
The format carries no binary header or magic bytes and uses the text/plain MIME type, so any text editor can open it. Comments use * at the start of a line, // for inline notes, or /* … */ for multi-line blocks. Do-files support the full Stata programming vocabulary: local and global macros, forvalues and foreach loops, conditional logic, and calls to .ado program files.
Do-files work hand-in-hand with .dta Stata datasets - a typical script loads a dataset, cleans and transforms the data, runs statistical models, and exports results. Output is often captured in SMCL log files. Stata's built-in Do-file Editor provides syntax highlighting and a direct run button; Visual Studio Code with the Stata Enhanced extension is a popular alternative for larger projects.
Security & safety
RISK: LOWA do-file is harmless to open in a text editor, but executing it runs its commands. A malicious Stata do-file could call shell commands (Stata's 'shell'/'!' syntax) or delete files, so review scripts from unknown sources before running them in Stata - the same caution you'd apply to any script.
Format details
in a nutshell- Java Servlet URL mapping (*.do) - Not a real file - a Struts-era URL suffix mapped to a controller servlet by the web server; nothing to download or open.
- ModelSim / QuestaSim DO macro - A Tcl-based macro script that automates HDL simulation in FPGA/ASIC and digital-design workflows.
Programs that open DO files
Technical details
deep spec| File type | Plain-text Stata command script |
| Developed by | StataCorp |
| MIME type | text/plain |
| Encoding | UTF-8 or ASCII plain text; no binary header or magic bytes |
| Execution command | `do filename.do` or `run filename.do` entered in the Stata command window or another do-file |
| Comment syntax | `*` at line start for a full-line comment; `//` for inline; `/* … */` for multi-line blocks |
| Line structure | One Stata command per line; long commands continued onto the next line with `///` |
| Macro support | Local macros (`local macname`) and global macros (`global macname`) for reusable text substitution |
| Loop constructs | `forvalues` for numeric ranges; `foreach` for lists of items such as variable names or file paths |
| Conditional logic | `if` qualifiers on individual commands and `if`/`else` block control flow |
| Typical use | Reproducible data cleaning, statistical modelling, and batch output generation |
| Related formats | `.ado` (Stata programs), `.dta` (Stata datasets), `.smcl` (Stata log files), `.sthlp` (Stata help files) |
| Operating systems | Windows, macOS, Linux - wherever Stata is installed |
| Editor support | Stata built-in Do-file Editor (syntax highlighting, direct run); VS Code with Stata Enhanced extension; any plain-text editor |
| Released | 1985 (Stata 1.0); do-file workflow standard ever since |
| Specification | www.stata.com |
DO conversions
Community Q&A
asked by usersNo questions yet - be the first to ask about DO files.