stata-exec

Send code to Stata from Atom

kylebarron

8,251

3

Bug Reports

1.8.6

MIT

GitHub

stata-exec

Send code to Stata from Atom. This package supports Windows, MacOS, and Linux.


While 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.


run-command

News

Installation

In the terminal run apm install stata-exec or go to Settings > Install and search for stata-exec. This package depends on language-stata, which you should be prompted to install if needed.

MacOS

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

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.

  1. Make sure you've installed this package and language-stata. In the command prompt, run apm install stata-exec language-stata or go to Settings > Install and search for stata-exec and language-stata.

  2. Install this specific version of the program Node to your computer. Use the default installation settings.

  3. 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:

    `-- windows-build-tools@2.2.1
      +-- chalk@2.3.2
      | +-- ansi-styles@3.2.1
      | | `-- color-convert@1.9.1
      | |   `-- color-name@1.1.3
    ...
    
  4. 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 atom -v.

    npm rebuild winax --runtime=electron --target=ELECTRON_VERSION --disturl=https://atom.io/download/atom-shell --build-from-source
    
  5. 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.

    1. In the installation directory, right-click on the Stata executable, for example, StataSE.exe. Choose "Create Shortcut".
    2. 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".
    3. 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.

  6. Restart Atom.

Now you can open up a Stata do-file and run code! See Usage for more details.

Linux

Important: Linux dependencies changed in version 1.6.0. Linux users must install xdotool and xclip.

On Ubuntu:

sudo apt install xdotool xclip

Usage

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
Run ctrl-enter Run selection or current line in Stata.
Run All shift-enter Run selection or current line in Stata and move down.
Run Batch ctrl-alt-d Run selection with do instead of interactively pasting commands.
Run And Move Down shift-ctrl-D Run entire file in Stata. (This runs do "/path/to/current/file")
Run Paragraph ctrl-alt-p Run the previous command.
Run Previous Command shift-ctrl-C Change Stata's working directory to that of current file.
Run Program shift-ctrl-G Run paragraph under current cursor. A paragraph is a region enclosed by whitespace.
Set Working Directory shift-ctrl-R Run program definition under current cursor. See note below.

For 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

Note that end must be on a line by itself to be identified as the end of the program.

Configuration

All configuration can be done in the settings panel (Settings > Packages > stata-exec). The available options are listed below:

Notes

Troubleshooting and Known Issues