Skip to content
Make Sublime Text 3 interact with Stata on Linux
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information. New Instructions May 8, 2017 Copy Paste Works May 8, 2017


How to get Sublime Text 3 to interact with Stata on Linux Systems.

So far I'm not aware of any other working solution. If you know one, please let me know! This is my first version (08 May 2017) and still work in progress. I will give you some guidelines how to get Sublime Text and Stata to interact with each other on a basic level.

1.) You will need to install Sublime Text.

2.) You will need the following Linux packages: wmctrl, xdotool, xclip, xautomation

3.) Install the Package Stata Enhanced (

4.) You should place a symbolic link of your stata executives (e.g. /usr/local/stata14/xstata-se) in '/usr/local/bin'.

5.) Download the file '' and place it anywhere you want. My recommendation is to place it into '~/.config/sublime-text-3/Packages/SublimeStataEnhanced'.

In what follow the path to this file is called DIR.

Edit the file '' if necessary to choose your version of Stata (to do this you will have to replace the code on line 13 and 16).

6.) Edit Stata.sublime-build ('.config/sublime-text-3/Packages/SublimeStataEnhanced') and replace the content with

{ "cmd": ["sh DIR/ $file"], "file_regex": "^(...*?):([0-9]*):?([0-9]*)", "selector": "source.stata", "shell": true, }

If everything is working correctly you should be able to run complete 'do-files' using the shortcut "Ctrl + b".

7.) Now you will need to edit the file ''. Paste the following code into the function 'text_2_stataCommand' after switch_focus = "":

if sublime.platform() == "linux":
    # Get the path to the current file
    filename = self.view.file_name()
    filepath = os.path.dirname(filename)

    # Write the selection to a temporary file in the current directory
    dofile_path = os.path.join(filepath, '')
    this_file = open(dofile_path, 'w')

    # Get ST version for returning focus to ST
    if int(sublime.version()) > 3000:
        st_name = "Sublime Text"
        st_name = "Sublime Text 2"

    cmd = "sh DIR/" + " " + '"' + dofile_path + '"'

8.) Edit your key bindings in Sublime Text and add the following between the brackets:

{ "keys": ["ctrl+d"],
  "context": [
  {"key": "selector", "operator": "equal", "operand": "source.stata"},]

Now you should be able to run the selected code with "Ctrl + D". The current line will be send if no code is selected.

I hope this works... Please let me know if you have any questions or recommendations for improvement.

You can’t perform that action at this time.