6

This SO question led me to try Sublime Text 3 as a replacement for Stata's do file editor on Linux (full instructions here).

Syntax highlighting works and a Ctrl+B shortcut sends the whole do file to Stata.

Is there a way to send only a selection of lines to Stata?

Community
  • 1
  • 1
radek
  • 7,240
  • 8
  • 58
  • 83
  • 1
    Stata has an underlying API that lets people script it (see http://www.stata.com/automation/). You can access that API via Applescript on OS X (which is how this plugin works: https://github.com/andrewheiss/SublimeStata13), and it seems like it's accessible via VB.net on Windows, but I don't know what Linux could use. Ideally some sort of Python API would make it work universally. – Andrew Nov 04 '13 at 23:59
  • @Andrew Thanks for the tip. I was aware of Win automation possibilities. But do prefer to stick to Linux. Sadly, Notepad++ is probably the last thing I'm missing from my Win machine. And it doesn't seem that there is an easy way around it. – radek Nov 05 '13 at 00:32
  • 1
    There has to be some way. Some guy at NASA has a rudimentary Python/Stata bridge (see http://www.stata.com/meeting/sandiego12/materials/sd12_fiedler.pdf and http://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/20130013847_2013013651.pdf) but it seems to only work in Windows. Maybe something like [xautomation](http://hoopajoo.net/projects/xautomation.html) would work, scripting some sort of copy/paste process to the Stata command window. – Andrew Nov 05 '13 at 01:21
  • @Andrew Thanks again. That looks pretty good. Will try to investigate that further. – radek Nov 05 '13 at 10:07

1 Answers1

2

Yes you can. First you need to find the name of the python function that does it. For the SublimeStata Enhanced package , it corresponds to the function text_2_stataCommand in the file text_2_stata.py.

Second, you need to add a shortcut for this function in the Key Binding user file, where you put the function name in the command field (the suffix Command must be removed and separations are indicated by underscores instead of capital letters).

{ "keys": ["super+shift+b"],
"command":"text_2_stata",
"context": [
{"key": "selector", "operator": "equal", "operand": "source.stata"},]
},
Matthew
  • 2,628
  • 1
  • 20
  • 35
  • If this is your first/only user keybinding: Go to Preferences > Key Bindings – User. Put the code above between the two square brackets that are provided for you, and save the file. – Nils Enevoldsen May 19 '15 at 15:20
  • Also, if you are using Stata 13+, use text_2_stata13 instead of text_2_stata. – Nils Enevoldsen May 19 '15 at 16:19
  • I came across this post as I was looking for a Mac solution to the same problem and is working fine. Can I ask, if there is a possibility to send a whole file not only the selection to Stata? – Konrad Jul 03 '15 at 14:24