Skip to content

Using Stata in Jupyter Lab

Currently, there are two mainstream solutions for using Stata in Jupyter Lab:

  1. PyStata, provided by Stata, allows calling Stata in a Python notebook with the Python kernel.
  2. Pros: It integrates closely with Python, allowing direct input of Python data into Stata. After running Stata's statistical commands, the results can be extracted back to Python for further processing.
  3. Cons: Syntax highlighting is not currently supported.
  4. Example: PyStata Example

  5. Kyle Barron's Stata Kernel.

  6. Pros: It provides a native Stata experience and supports syntax highlighting.
  7. Cons: It can only use Stata's inflexible export methods.
  8. Example: Stata Kernel Example

Based on personal experience, if there is no need to process data specifically with Python, using the Stata Kernel provides a better experience.

1. PyStata

Refer to the official tutorial.

2. Stata Kernel

Refer to Kyle Barron's tutorials:

Stata's location needs to be specified during the configuration process

Typically, depending on the installed version, the specific executable file location of Stata on a Linux system is as follows:

MP version:

/usr/local/stata17/stata-mp

BE or SE version:

/usr/local/stata17/stata

Last update: September 16, 2023