Setup
The path to the Python executable is set using:
python set exec "path_string"
Stata can list recognized Python environments with python search.
To make this setting permanent, use the permanent option.
Python REPL
A Python REPL is entered with the python command. It prints to the screen a reminder that the end command is used to exit the environment.
Stata local variables are accessed with quotations.
. local int_var = 3 . local str_var = "This is a Stata string" . python ---------------------------------------- python (type end to exit) ----------- >>> `int_var' 3 >>> "`str_var'".split(" ") ['This', 'is', 'a', 'Stata', 'string']
Within the REPL, the stata context submits commands to the parent Stata shell.
Python Scope
A Python scope can be entered with python: (similar to defining function in Stata). Then Python environment is exited upon leaving the scope.
Python SFI Module
A foreign function interface module is also available.
from sfi import Data pymake = Data.get('make')
This can even be used within the Python REPL that is running within the Stata shell.