Skip to content

Configuration

There are a few more steps to get the plugin work. You can find a video guide from installation to configuration at the bottom of this page.

Configure StataEditor

There are a few required and optional arguments to be specified. Open Sublime Text > Preferences > Package Settings > StataEditor > Settings – User. An empty file will pop up. You can copy the template setting below, paste it into the empty file, and change the Stata version and path to your own.

{
    /* true = Add an empty line at the end of the do file. It's recommended to
       set it to be true, since Stata builtin editor needs an empty line at the
       end of a do file to run properly. (This empty line is automatically done
       in Stata default do file editor so you may not realise it before)
    */
    "ensure_newline_at_eof_on_save": true,

    /* Your Stata `.exe` path */
    "stata_path": "C:/Program Files/Stata17/StataMP-64.exe",

    /* Your Stata version. We only need the integer part. That is, type 16 if
       your Stata version is 16.1
    */
    "stata_version": 17,

    /* Character encoding. "utf-8" is recommended for Stata 15 and later. For
       earlier versions and non-latin environment (e.g. Stata in Chinese or
       Japanese), you may want to use "gbk"
    */
    "character_encoding": "utf-8",

    /* true = enable variable auto-completion */
    "variable_completions": true,

    /* true = enable function auto-completion */
    "function_completions": true,

    /* true = enable command auto-completion */
    "command_completions": true,

    /* The working directory in Stata when you establish an initial Stata
       connection from Sublime Text.
       "current_path" = where your currently opened do file is located
    */
    "default_path": "current_path",

    /* Which types of files should be included in filename auto-completion. Note
       that if your folders containing an huge amount of files, this can lead to
       memory leaks. If so, simply change the setting to "false".
       false = disable such auto-completion
       To enable file completions, enter the file extensions you wish to be
       enabled separated by commas
    */
    "file_completions": "dta, do, py, xlsx, xls, csv, txt",

    /* The waiting time in seconds from that Stata is launched until the
       commands are being sent. With zero waiting time, Stata may be launched
       twice. Only matters for Stata 15 and later. Change waiting time as
       needed. The default 0.5 seconds is often fine
    */
    "waiting_time": 0.5
}

Example setting

To say, I use Stata 16.1, and it's installed in D:/Economics/Stata16/StataMP-64.exe. There are thousands of files in my project, so I want to disable file name auto-completion to speed up the plugin.

{
    "ensure_newline_at_eof_on_save": true,
    "stata_path": "D:/Economics/Stata16/StataMP-64.exe",
    "stata_version": 16,
    "character_encoding": "utf-8",
    "variable_completions": true,
    "function_completions": true,
    "command_completions": true,
    "default_path": "current_path",
    "file_completions": false,
    "waiting_time": 0.5
}

Register the Stata Automation Type Library

To allow Sublime Text to talk with Stata, we need to use a Stata Automation object. You may refer to the official guide, or in short:

  1. Press Win+R, type cmd, and then press Ctrl+Shift+Enter to run Command shell as Administrator. You will see a window with prompt like C:\WINDOWS\system32>
  2. Go to Stata installation directory using cd. E.g., if your Stata in in C:/Program Files/Stata17, then type cd "C:/Program Files/Stata17" and press Enter. The quotes are necessary if the path includes whitespace. After this step, the prompt will change to C:\Program Files\Stata17>
  3. Type ./StataMP-64.exe /Register and press Enter to register. If you use Stata SE or other version then change the executable filename accordingly
  4. Nothing fancy will happen but it's already properly registered

CMD, PowerShell, Terminal?

Newer Windows comes with more than one command-line shells, including Command Prompt, Terminal or PowerShell. The above steps may or may not work. Whenever possible, use Command shell (cmd).

Need admin rights

We must run ./StataMP-64.exe /Register as admin. If you see errors like AttributeError: 'module' object has no attribute 'stata' in Sublime Text console, please re-register Stata library as admin. See #1 for more details.

Close and restart Sublime Text. Now we are ready to start!

Copilot (optional)

GitHub Copilot uses Codex, which is a descendant of GPT-3 by OpenAI, the company that created ChatGPT, to suggest code in near real-time. Basically, you write the comment or part of the code, and Copilot auto-complete the rest for you. It's a great tool to boost productivity! There is no official support of Copilot for Sublime Text, but community members have made it possible. One such tool is LSP-copilot. You can find the installation and setup instruction on its repository.

Copilot may not work well with Stata

Personally I discourage using Copilot for Stata. The reason is simple: Copilot does not understand Stata syntax well, partly due to a lack of Stata code in its training data. (Just think about how many CS papers publish their code on GitHub, and how many econ papers have their replication files available online...) As a result, it may suggest wrong code very often. Below is an example where Copilot is wrong (the coefficients are completely hallucination).

Video Tutorial