Send code to Stata from Atom. This package supports Windows, MacOS, and Linux.
stata-exec will still be supported, I suggest users use the new Stata Jupyter Kernel along with the Hydrogen package instead. It can show Stata results inline and works with Windows, macOS, and Linux. It is not necessary to install
stata-exec to use
- Version 1.7.0 supports batch sending of code selection with
- Version 1.6.0 uses a new program on Linux to send code to Stata. It seems way better; faster pasting and supports unicode characters.
In the terminal run
apm install stata-exec or go to Settings > Install and search for
This package depends on
language-stata, which you should be prompted to install if needed.
MacOS has no dependencies but you must select the flavor of Stata you own in the package's configuration. Learn more in the configuration section below. Then head to the usage section for more details on running code.
This package can potentially work on Windows but is very hard to get right, so it's not officially supported. I would strongly recommend Windows users try
stata_kernel which has a much easier installation process on Windows.
Windows installation has a few steps, and I haven't been able to perfectly reproduce the working package on all computers. I hope to make this easier in the future, but for now this will have to do. Sadly, at this point you need administrator privileges to install this for Windows.
Make sure you've installed this package and
language-stata. In the command prompt, run
apm install stata-exec language-stataor go to Settings > Install and search for
Install this specific version of the program Node to your computer. Use the default installation settings.
Open up an administrator PowerShell (you can right click on the Windows icon at the bottom left and select "Windows PowerShell (Admin)") and type in:
npm install --global --production windows-build-tools
This took me 5-10 minutes to install. This is installing Python and other tools needed to install the package in the next step. When finished you should see a long list of names in a tree, like this:
`-- firstname.lastname@example.org +-- email@example.com | +-- firstname.lastname@example.org | | `-- email@example.com | | `-- firstname.lastname@example.org ...
Open up Command Prompt (type
cmdin the search bar in the dock, and it will be the first result) and type in:
cd %USERPROFILE%\.atom\packages\stata-exec npm install winax --python=%USERPROFILE%\.windows-build-tools\python27\python.exe atom -v
Then enter the following, where you need to replace
ELECTRON_VERSIONwith the text following "Electron" in the output of
npm rebuild winax --runtime=electron --target=ELECTRON_VERSION --disturl=https://atom.io/download/atom-shell --build-from-source
Link the Stata Automation library. The following steps worked for me on Windows 10. The Stata executable is most likely in the folder
C:\Program Files (x86)\Stata15.
- In the installation directory, right-click on the Stata executable, for example, StataSE.exe. Choose "Create Shortcut".
- Right-click on the newly created "Shortcut to StataSE.exe", choose "Property", and change the Target from "C:\Program Files\Stata13\StataSE.exe" to "C:\Program Files\Stata13\StataSE.exe" /Register. Click "OK".
- Right-click on the updated "Shortcut to StataSE.exe"; choose "Run as administrator"
While you're doing that, add the path of the Stata executable to the "Stata Path" option in the settings.
Now you can open up a Stata do-file and run code! See Usage for more details.
sudo apt install xdotool xclip
Code can be run using either the Command Palette or with keyboard shortcuts.
To open the Command Palette, press cmd-shift-P / ctrl-shift-P, and then start typing
Stata Exec. The available commands will be shown in the drop-down menu.
The following are the default keyboard shortcuts (on macOS, use cmd instead of ctrl). Keyboard shortcuts can be personalized in your
keymap.cson file. More instructions here.
|Command||Default keyboard binding||Description|
||ctrl-enter||Run selection or current line in Stata.|
||shift-enter||Run selection or current line in Stata and move down.|
||ctrl-alt-d||Run selection with
||shift-ctrl-D||Run entire file in Stata. (This runs
||ctrl-alt-p||Run the previous command.|
||shift-ctrl-C||Change Stata's working directory to that of current file.|
||shift-ctrl-G||Run paragraph under current cursor. A paragraph is a region enclosed by whitespace.|
||shift-ctrl-R||Run program definition under current cursor. See note below.|
Run Program, if there exists
program drop on the line before
program define, the line including the former will be included in the selection. For example, all the lines in the below snippet would be sent to Stata:
cap program drop myProgram program define myProgram // program contents end
end must be on a line by itself to be identified as the end of the program.
All configuration can be done in the settings panel (Settings > Packages > stata-exec). The available options are listed below:
- Stata Path (used for Windows only)
- Absolute path to Stata executable. The default setting will most likely need to be changed to reflect your install location and Stata flavor.
- Which App (used for macOS only)
- Select StataIC, StataSE, or StataMP depending on which version of Stata you have.
- Select XQuartz if you want to run selections in session of Stata on a remote Unix server. To set this up, you need to have Stata already open in XQuartz; Atom will not open it for you. In your terminal, you'll need to do something like
ssh username@host -Y, likely followed by
xstata. This package's commands to run the entire do file and set the working directory are not supported on XQuartz.
- Advance Position
- If checked, move cursor to the next line/paragraph after running the current line/paragraph.
- Focus Window
- If checked, bring the Stata window to focus when sending code.
- Otherwise, code runs in the background and the screen remains focused on Atom.
- If checked, a pop-up notification will appear when a paragraph or function is not identified.
- Skip Comments
- If this and Advance Position are checked, after running a line the cursor will move to the next uncommented line.
- Paste Speed (used for XQuartz only)
- This value changes the amount of time the program waits between switching to the XQuartz window, pasting code, and sending "enter". The only way to send code to XQuartz is to use the clipboard, and the responsiveness of this process will depend on the speed of your internet connection. If the copy-pasting isn't working, try increasing the value. Decreasing the value will run your code faster. Value must be between 0.1 and 10.
Troubleshooting and Known Issues
- Run All doesn't run the last line of the do file.
- Stata needs there to be a newline character following the last line of text. Add an empty line to the end of the file and it'll work.
- On Linux, the Stata GUI window must be the only program open with a window title of
Stata/. If not, it appears the program will alternate between open Stata windows when pasting. xdotool seems to let me choose which Stata window to send text to, so maybe that could be put into a more useful function in the future.