in software

Stata bundle for TextMate

Rumor has it that there’s an extant Stata bundle for TextMate. The original package link is a dead, but Gabriel Rossman was kind enough to send me a copy of his installed bundle.

With thanks to the author, Timothy Beatty, here’s the original bundle:

Download Stata Bundle

Stata bundle (original)

For those wanting a little extra functionality, George MacKerron described a method to add tab-completion for Stata variables. I’ve added his code to this version of the Stata bundle. (N.B. If your Stata application is not named “Stata”, you’ll need to make one small change. Open TextMate’s Bundle Editor; then, in the Stata bundle’s Complete Variable command, change the “appname” variable in line 6 to reflect your app’s true name, e.g. “StataMP”.)

Download Stata Bundle with tab-completion

Stata bundle (with tab-completion)

Update: I’ve learned that two forward slashes can also be used in Stata for comments, including inline comments. To properly highlight this in Textmate, open the Bundle Editor > Stata > Stata. At the end of this file is the ‘’. Change the match line to this:

match = '((^|\s)*|//).*$';

(N.B. As Sean points out below, make sure the single-quotes are straight, not curly, when you paste this line. Otherwise TextMate will throw an error.)

For those with something to say:



  1. Ha! Great, just what I was looking for. Fun fact: Got here through a google search. Man, the I School rocks.

  2. Hi,

    thanks for this great work, it is a fantastic help!!!

    The only problem I have is with you ‘Update’. When trying to make the changes as instructed I get the message:

    line 41:36: expecting ‘;’, found ‘(‘

    Any idea what to do about this? I am currently running Stata IC 11.1


  3. Sam—my guess is that you inadvertently removed the semicolon from the previous line. It should look like this:

    Hope this helps,

  4. Hi Dan,

    thanks for your quick response but that does not seem to be the issue…

    This is how it looks like for me and I still get this error:

        {   name = 'string.quoted.single.stata';
            begin = '`';
            end = "'";
            patterns = (
                {   name = 'constant.character.escaped.untitled';
                    match = '\\.';
        {   name = 'comment.block.stata';
            begin = '/\*';
            end = '\*/';
        {   name = '';
            match = ‘((^|\s)\*|//).*$’;


    Let me know if you have other ideas, if not it’s no big deal, it works great without this part too!

  5. I’m not sure what error you’re getting but this looks right to me. You could always get in touch with the TextMate developer or post to the TextMate forums… Good luck!

  6. Sam:

    I had the same problem – it’s something to do with the copying and pasting of ascii characters. Just delete the curved single quotes after pasting (before the left paren and before the semicolon) and replace them with single straight quotes instead of single curved quotes.

  7. Just a heads up… Chrome will rename this file from to simply .zip. It will do this without telling you! Couldn’t figure it out until I tried downloading the bundle again in Safari. Just thought I’d let people know in case anyone else is having the same problem.

  8. I was having problems with compound quotes with this bundle. If you open up the bundle editor and select the first option under Stata (also called stata) so that you can edit the language definition. Scroll to the end and you’ll find two definitions for strings. Insert the text below and you should be sorted.

        {   name = 'string.quoted.compound.stata';
            begin = '\`"';
            end = '"''';
            patterns = (
                {   name = 'constant.character.escaped.untitled';
                    match = '\\.';
  9. Thanks for updating the code. Really helpful!

    The bundle works great, but I run into a problem when I send a selection of code involving a local macro from TextMate to Stata. The temporary file does not ‘remember’ the local macros (globals are fine).

    I set TextMate to save my temporary do file in /Code/Stata. I always use global macros to define my data directories as /Code/Stata/Projects/…/Data.

    Do you know of a way to get the local macros to work when sending selections from TextMate to Stata?

    Thanks Eric

  10. I want to fix an annoying issue with the Stata bundle for Textmate. When using the “Send file to Stata” or “Send Selection to Stata” actions, it changes the working directory of Stata to the location of the .do file being executed. This is particularly a problem with “Send Selection to Stata” because it means that you have to specify the full path name for any dataset you are opening or saving. Does anyone have a solution to this?

    Here is the code within the bundle. Is there a way to send the file to Stata without making Stata change directories to /applications/stata/ ?

    echo “$TMSELECTEDTEXT” > “/applications/stata/”

    osascript -e “tell application \”StataMP\” activate open POSIX file \”/applications/stata/\” end tell”

  11. I am a beginner in Textmate. I installed the Stata bundle. When I send the “Selection to Stata” nothing happens. Have I missed something? Any help would be welcome.

  12. Tab completion for Stata variables I tried this command and it didn’t work. It says “28:71: execution error . File stata wasn’t found (-43). No variables found.”

    Any help would be appreciated.

  13. I think I might have a fix for Fabian and Joseph’s problem. Posted at but copied here too.

    When using the send selection to stata command in the bundle, this will fail sometimes because it creates a temporary file in the stata application directory. Anything which depends on relative references will therefore be broken. If you modify bundle so that it saves the file in your current directory (see below) then apart from these little files proliferating, everything gets better.

    #Modified 2012-01-20 13:49 
    # Now will automatically work from the current textmate directory
    #!/usr/bin/env bash
    [[ -f "${TM_SUPPORT_PATH}/lib/" ]] && . "${TM_SUPPORT_PATH}/lib/"
    echo "
    " > "${TM_DIRECTORY}/"
    osascript -e "tell application \"Stata\"
        open POSIX file \"${TM_DIRECTORY}/\"
    end tell"

    Hope that helps

  14. Hey, I was wondering that with Stata installed to run in the terminal, if I could integrate a little cmd – R action into TextMate, any thoughts?

  15. I’ve used Steve Harris’ update from above and Huebler’s original Notepad++ files to get the ability to run Stata code directly from Sublime Text 2.

    Just download Huebler’s files from:

    …then in ST2 go to Preferences>Key Bindings: User, and paste in the following code: [ { “keys”: [“f9”], “cmd”: [“C:\\ado\\personal\\rundo.exe”, “$filepath//$filename”] } ]

    …replacing with your preferred keybind and directory structure, of course. You can do the same with the rundolines.exe file as well.

  16. Hi there, Thanks a lot for publishing the Stata bundle! I’ve used it for months. It work just perfect. But I just updated to Mountain Lion, and it does not work properly anymore. It’s much slower, and it easily freezes. Do you have any suggestion? Any help would be very appreciated. Thanks, DQJ PS: if it helps, I’m using Stata 12

  17. After upgrading to Mountain Lion, I experience the same problem as described by DQJ. I wonder if anyone has come up with a solution yet?

    Thanks, Chris

  18. I believe that I found a solution to the problem that under Mountain Lion and (in my case) with Stata 11, Textmate hangs after sending a file or a selection to Stata. The problem seems to be that Applescript is waiting for a response from Stata after opening the file, but Stata does not send one. So, including the statements “ignoring application responses” and “end ignoring” before and after the “open POSIX file” command solves the problem for me:

    osascript -e “tell application id \”S5x8\” activate ignoring application responses open POSIX file \”${TM_FILEPATH}\” end ignoring end tell”

  19. David is the man! That fixed my Mountain Lion problem.

    Just to be clear: the quotation marks around ignoring application responses is for the purpose of exposition. No quotes are needed in actual code.

  20. Hi David,

    Thanks for sharing the solution with all of us!

    I’ve very small notions of programming (if any). Could you please specify the steps to follow to implement your solution?

    I opened Terminal and simply copy-pasted the two code lines you posted. But that did not work for me. I’m sure I’m doing something wrong. Thanks a lot.

  21. Hi,

    Thanks for making this available.

    I have put my forked version of the bundle without tab completion on github here:

    Would you mind if I asked the TextMate repository for it to be included there so it is available through the Bundles preference pane in TextMate 2 alpha.

    thanks again, Tom

  22. Tom,

    Of course! I posted the bundle because it wasn’t available anywhere else, but an official repo would be more suitable.

    Best, Dan

  23. Dear all,

    Would you mind clarifying which bundle is what?

    • This page has the original Tim Beatty bundle, which takes a keyword approach to Stata syntax and colors a finite list of commands, plus comments.
    • Phil Schumm’s bundle, which does not have commands-as-keywords but instead regex to identify control flow statements and other things, is in that repo: — and in that repo too, with a list of issues:
    • As for Tom Palmer’s repo, I’m not sure which one it reflects.

    Thanks in advance for any help sorting out which is which.

  24. I have been using this bundle with Stata 11 for several years now. I just upgraded to Stata 13 and now the “Send File to Stata” and “Send Selection to Stata” don’t work properly anymore. Rather than executing the do file, Stata opens it up in its own do file editor. Does anyone know how to fix this?

  25. Hi Dan,

    Thanks a lot for this post, it is extremely useful!

    I was wondering (i) if there was an easy way to change the colours. For example if I wanted to have a white background, or change the orange command for red. (ii) how we could add a colour. For example, I am using “* ” at the beginning of a line to comment out a command so it is nice that it is light grey. But I would like to have anything starting with “**” in a more readable/contrasted colour as I am using this to annotate my do files and the light grey is hard to read on the black background.

    If you have any tip or suggestion, that would be great.


  26. @ Steve Harris

    I appreciate the work around for using send selection to stata. It does gets closer to what I want. However, it only works if the data and code are in the same directory. If you have your code in a different directory from the data, then you run into the same problem. Stata switches to the code directory (which is the current directory of the textmate file) and then it can’t find the data.

    I don’t see a way around this though with the current implementation which saves the selected text as a file and has Stata open it.

    Is there a way to send the lines of code directly to Stata without saving them to a file?