This extension contains a set of tools for working with Stata:
- Language grammar for syntax highlighting (from Kyle Barron)
- Ability to send code to the Stata application (from poidstotal)
- This feature makes VSCode effectively a do file editor
- Interactive window support using
nbstata. See below
Interactive window allows you to use a plain .do file and have an interactive REPL in VSCode.
The idea is that you take your regular .do file and sprinkle in * %% comments.
These comments will mark "code cells" which are set of lines of code that you want to run all together.
When you hit Run Cell (or use a keyboard shortcut), then those lines are sent to the interactive window and the results are displayed below.
By default you can use cmd+shift+d to run all the cells (in order) and cmd+enter to run the current cell and move to the next cell.
I recommend adding two more keyboard shortcuts (cmd+[ for Go to Previous Cell and cmd+] for Go to Next Cell).
This allows you to jump around the do file according to your cell markers
This feature uses the nbstata jupyter kernel by Tim Huegerich.
- I used code from
stata-mcpthat will automatically installuv(to manage python packages) and setupnbstata. If you run in to any issues, see https://github.com/hanlulong/stata-mcp/tree/main?tab=readme-ov-file#python-environment-management
These commands allow you to execute Stata code directly from VSCode without switching applications.
You can either set up keyboard shortcuts or use the command palette (launch with cmd+shift+p and then search Send to Stata)
There are four commands for sending code to Stata:
Send to Stata: All LinesSends the entire file to Stata (cmd + shift + d)Send to Stata: Selection / Current LineSends the currently selected text to Stata. If no text is selected, then the current line is sent (cmd + enter)Send to Stata: Above LinesSends all code above the cursoSend to Stata: Current Line and BelowSends all the code on the same line as the cursor and below
This repository uses a lot of code MIT licensed language-stata by Kyle Barron , poidstotal
, and Han Lu Long
into a single extension.
Please give a star to each project to say thanks!
