Code sharing | Stata All in One
logo
Table of Contents
Stata All in One
One VS Code extension tailored for Stata users
| Version: 0.2.13 | Author: Zihao Viston Wang | 翻译: 中文版本 |
All-in-one Stata experience: Syntax Highlighting + Code Hints + Smart Outline + Code Execution + Quick Editing!
Stata All in One is derived from Stata Outline.
Sponsors
Special thanks to RedNote user Rich**d and WeChat user 早起**阳光 for their generous donations and support for this project.
Features
1. Enhanced Syntax Highlighting & Code Completion
- Full Syntax Highlighting and Code Completion Support: Integrates Stata Enhanced syntax engine1, providing precise syntax highlighting and code completion for
.dofiles (under MIT License). - Custom Command Highlighting: Supports highlighting for commonly used third-party commands (e.g.,
reghdfe,ivreghdfe,gtools), freely configurable in settings.
2. Smart Outline & Structural Navigation
- Multi-level Outline Recognition: Automatically detects comment lines from
**#to**######as hierarchical headers, supporting up to 6 levels.- Shortcuts:
Ctrl/Cmd + 1-6to quickly convert to the corresponding header level;Ctrl/Cmd + 0to revert to a standard code line.
- Shortcuts:
- Cursor Auto-Follow: The outline view automatically highlights and navigates to the corresponding section as the cursor moves in the editor.
- Setup: Click the “···” button in the top-right of the Outline view and check “Follow Cursor”.2
- Multi-level Numbering: Optional display of logical numbering (e.g.,
1.1,1.2.1) within the outline (must be enabled in settings). - Auto-Sync Numbering: When enabled, the extension automatically adds or removes numbering directly within the
.dofile based on the outline structure. program defineBlock Recognition: Displays program names in the outline view for easy navigation and management of custom programs.
3. Code Execution (Stata Interaction)
- Platform Support: Seamlessly integrates with Stata on both macOS and Windows without requiring additional extensions.
- Multi-Scenario Execution Strategies:
- Section Execution: When the cursor is on a header line (e.g.,
** # Title), clicking the ▶️ button or pressingCtrl/Cmd + Dwill execute the entire section from that header to the next same-level or higher-level header. - Single Line Execution: When the cursor is on a regular code line (no selection), clicking the ▶️ button or pressing
Ctrl/Cmd + Dwill only execute that specific line. - Selected Code Execution: When multiple lines of code are selected, clicking the ▶️ button or pressing
Ctrl/Cmd + Dwill execute the selected code lines. Supports fuzzy selection - no need to precisely select the first or last line of a code segment; the system will automatically capture and run all lines covered by the selection.
- Section Execution: When the cursor is on a header line (e.g.,
- ⚠️ Note
- On Windows, code execution relies on PowerShell automation. If your machine is slow or occasionally misses keystrokes, consider increasing the step delay (setting
stata-all-in-one.stataStepDelayOnWindows). - On Windows, if Stata does not wake up and run the code when running code, please try to set
truefor theClose Stata other windows before sending codeoption (settingstata-all-in-one.closeStataOtherWindowsBeforeSendingCode).
- On Windows, code execution relies on PowerShell automation. If your machine is slow or occasionally misses keystrokes, consider increasing the step delay (setting
4. Efficient Separator Lines & Styling
- Quick Insertion: Supports various symbols to significantly enhance code readability.
- Standard Separators: Use
Ctrl/Cmd + Symbolto quickly insert separator lines:Ctrl/Cmd + -(Dash) |Ctrl/Cmd + =(Equal) |Ctrl/Cmd + Shift + 8(Asterisk)
- Custom Separators:
Ctrl + Alt + S(Windows) |Ctrl + Cmd + S(macOS), where S stands for “Separator”.- After pressing the shortcut, simply input your desired character to generate the corresponding separator line.
- Standard Separators: Use
- Intelligent Wrap Mode:
- Blank Line Insertion: Generates a full-width separator line (length adjustable in settings).
- Non-blank Line Insertion: Pressing the shortcut once inserts above the line; pressing it again inserts below, creating a “wrapped” effect.
- Header Decoration: Select some characters of a header and press the shortcut to generate a title with balanced decorative symbols (e.g.,
**# === Title ===), without affecting outline recognition.- Centered Header: If using Header Decoration + Custom space separator, the header content will be automatically centered.
5. More Features
-
Enhanced Comments
- Toggle Comments: Quickly toggle line comments using
Ctrl/Cmd + /. - Optional Styles: Defaults to
//, with support for switching to other valid Stata comment delimiters in settings.
- Toggle Comments: Quickly toggle line comments using
-
Built-in Help
- Quick Help: For example, select
regressand press the shortcut keyCtrl/Cmd + Shift + Hto open Stata’sregresshelp page.
- Quick Help: For example, select
-
Smart Line Break
- One-Key Line Break: Use
Shift+Enterto insert Stata line continuation symbol///at the cursor position. - Smart Indentation: Automatically indent by 4 spaces
- One-Key Line Break: Use
-
Safe Rename Mode
- Rename Variable: Select a variable and press
F2to rename all occurrences in the current do-file. - Smart Validation: Automatically validates the new name to ensure it follows Stata naming rules and does not conflict with built-in commands or keywords.
- Command Protection: Intelligently prevents renaming Stata commands (e.g.,
reghdfe,outreg2) and their options (e.g.,absorb,ctitle).
- Rename Variable: Select a variable and press
- Auto
cdto Do File Directory- Auto Working Directory: When enabled, automatically sets Stata’s working directory to the do file’s location on first launch.
Keyboard Shortcuts
Click Keyboard Shortcuts to view the complete list of keyboard shortcuts.
Installation
Install from Extension Marketplace
- VS Code: Search for “Stata All in One” in extensions and install.
Download and Install (for Cursor, Trae and other VSCode-based IDEs)
- Download
stata-all-in-one-x.x.x.vsixfrom either source: - Open Extensions panel in your editor →
...→Install from VSIX.... - Select the downloaded
.vsixfile to complete installation.
Configuration
Search for “Stata All in One” in VS Code settings and configure:
Syntax Highlighting and Code Hints
- Custom Command Highlighting (
stata-all-in-one.customCommands)- User-defined Stata commands to highlight as keywords (array of strings). Default:
reghdfe. - Example:
["reghdfe", "ivreghdfe", "gtools", "winsor2", "outreg2"] - Requires reloading window after configuration.
- User-defined Stata commands to highlight as keywords (array of strings). Default:
Outline & Navigation
-
Display Multi-level Numbering (
stata-all-in-one.numberingShow)true: Outline displays1.1,1.2.1style numbering.false(default): Displays original headings.
-
Auto-update File Content (
stata-all-in-one.numberingAdd)true: When numbering is enabled, automatically update section titles in .do files to include numbers. Requires reopening .do filesfalse(default): Only displays numbering in outline, doesn’t modify file.
Code Execution
-
Show Run Button (
stata-all-in-one.showRunButton)true(default): Whether to show the run button in the editor title bar.false: Hides button.
-
Show Action Buttons (
stata-all-in-one.showActionButtons)true(default): Show the “Bug report” and “Sponsor” buttons in the editor title bar.false: Hide these buttons.
-
Stata Version on macOS (
stata-all-in-one.stataVersionOnMacOS)- [macOS] Stata version. Select between
StataMP,StataIC,StataSE. - Default:
StataMP
- [macOS] Stata version. Select between
-
Stata Path on Windows (
stata-all-in-one.stataPathOnWindows)- [Windows] Path to Stata executable file (e.g.,
C:\Program Files\Stata17\StataMP-64.exe).
- [Windows] Path to Stata executable file (e.g.,
-
Stata Step Delay (Windows) (
stata-all-in-one.stataStepDelayOnWindows)- [Windows] Delay between PowerShell automation steps (ms). Default:
100(min:50). Increase if your machine is slower or Stata misses keystrokes.
- [Windows] Delay between PowerShell automation steps (ms). Default:
-
Close Stata Other Windows Before Sending Code (Windows) (
stata-all-in-one.closeStataOtherWindowsBeforeSendingCode)- [Windows]
true: Close Stata helper windows (such as Viewer/Data Editor) before sending run commands. false(default): Keep those windows open and send code directly.
- [Windows]
-
Enable Ctrl+Shift+D for Run Shortcut (
stata-all-in-one.enableCtrlShiftD)
true: UseCtrl/Cmd+Shift+Das the run code shortcut.false(default): Use the defaultCtrl/Cmd+Dshortcut.
- Auto cd to Do File Directory (
stata-all-in-one.cdToDoFileDir)- `true` (default): Automatically `cd` to the do file's directory when Stata is first launched.false: Stata’s working directory is not changed on startup.
Code Style
- Comment Style (
stata-all-in-one.commentStyle)
//(default): Comment style used for toggling comments. Options include//,*, or/* ... */
- Separator Length (
stata-all-in-one.separatorLength)
- Total character length of the separator line (including the ‘** #’ prefix and separators). Default:
60
- Separator Symmetric (
stata-all-in-one.separatorSymmetric)
true: Add**at the end of separator lines to ensure visual symmetry (e.g.,** === title === **).false(default): Separator lines without the suffix.
Note: Changes take effect after reopening
.dofiles. WhennumberingAddis disabled, existing numbering in.dofiles will be automatically removed.
Buy me a coffee
If this extension has been helpful to you, feel free to scan the Alipay (left) or WeChat (middle) or Buy me a Coffee (right) QR code below to buy me a coffee ☕
Changelog
| Version | Changes | Release Date |
|---|---|---|
| 0.2.13 | On Windows, running code no longer resets a snapped or maximized Stata window to a smaller size, it will now keep the current window size unchanged. | 2026-03-12 |
| 0.2.12 | Windows: Added configurable option to close other Stata windows (Viewer/Data Editor) before sending code; Added configuration to toggle display of “Bug report” and “Sponsor” buttons. | 2026-03-05 |
| 0.2.11 | New optional feature: Auto cd to do file directory on first Stata launch (disabled by default). |
2026-03-02 |
| 0.2.10 | Refined code execution logic (Section/Line/Selection execution); Configurable run shortcut; F2 rename for variables. | 2026-02-27 |
See CHANGELOG.md for full version history.
-
Stata Enhanced syntax engine was developed by Kyle Barron, providing comprehensive support for the Stata language. This extension follows the MIT License. Thanks to Kyle Barron for his contribution! ↩︎
-
Sorry~ This is a VS Code GUI setting, I cannot control it through the extension. ↩︎