In Sublime Text 3, can I send a selection of a do file to Stata?
Asked Answered
A

1

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?

Andryc answered 23/8, 2013 at 20:43 Comment(4)
Stata has an underlying API that lets people script it (see stata.com/automation). You can access that API via Applescript on OS X (which is how this plugin works: 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.Landward
@Landward 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.Andryc
There has to be some way. Some guy at NASA has a rudimentary Python/Stata bridge (see stata.com/meeting/sandiego12/materials/sd12_fiedler.pdf and ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/…) but it seems to only work in Windows. Maybe something like xautomation would work, scripting some sort of copy/paste process to the Stata command window.Landward
@Landward Thanks again. That looks pretty good. Will try to investigate that further.Andryc
S
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"},]
},
Stadia answered 21/8, 2014 at 18:23 Comment(3)
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.Osteopath
Also, if you are using Stata 13+, use text_2_stata13 instead of text_2_stata.Osteopath
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?Juan

© 2022 - 2024 — McMap. All rights reserved.