Send code to Stata from Atom. This package supports Windows, MacOS, and Linux.
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.
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.
language-stata. In the command prompt, run
apm install stata-exec language-stataor go to Settings > Install and search for
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
cmd in 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_VERSION with 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.
Linux users must install Autokey. On Ubuntu, that's as simple as:
sudo add-apt-repository ppa:troxor/autokey sudo apt update sudo apt install autokey-gtk
You must then link the stata-exec.py file to your Autokey data directory. This is
~/.config/autokey/data/My Phrases by default, so you can add the file to that directory with the command
ln -s ~/.atom/packages/stata-exec/linux/stata-exec.py ~/.config/autokey/data/My\ Phrases/
This only needs to be done once. (Creating a symlink ensures that the script is always the most up to date version.) Additionally, the autokey program must be running for code sending to work. To do this, open up a new terminal and run
autokey-gtk; this process needs to be running each time you run code. (Alternatively, there's an option in Autokey's settings to start the program by default at login.)
Important: You cannot click anywhere while your command is being pasted to Stata. This package works on Linux by copying and pasting your commands (minus comments) to the Stata window, so if you click back in Atom while it's pasting, your commands will be pasted back into Atom and may crash Atom.
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 (Mac / Windows and Linux). These can be personalized in your
shift-cmd-R / shift-ctrl-R: run program definition under current cursor. 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 myProgramprogram define myProgram// program contentsend
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:
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.
Good catch. Let us know what about this package looks wrong to you, and we'll investigate right away.