Using Stata with Jupyter Notebook in Linux System

Sometimes, you might need Stata

It takes me a while to figure out how to use Stata with Jupyter Notebook in Linux system. Just write down the procedures and others could do it by following those steps.

Download .tar.gz file

Please download your file first with your Stata serial number.

Install

cd ~/Downloads
mkdir statainstall
tar -xvzf Stata14Linux64.tar.gz -C statainstall
sudo mkdir /usr/local/stata16
cd /usr/local/stata16
sudo ~/Downloads/statainstall/install

License

In order you configure the license file you just need to run ./stinit (you’ll need root privileges to write the file). Be sure to have the serial number, code and authorization. No need to disconnect from the interwebz here, even if you have an “alternative” license ;)

sudo ./stinit

Add directory to path

Add execution path

echo export PATH="/usr/local/stata16:$PATH" >> ~/.bashrc

You need to source your .bashrc so that the changes are effective:

source ~/.bashrc

After adding the install directory to yout path, you should be able to run the appropriate version of Stata from the terminal, e.g.:

stata  # or stata-se or stata-mp (depends on your version)

You should see the following prompt.

A screenshot of stata
Figure 1. Screenshot of Stata

Install stata_kernel

Follow this link and install stata_kernel.

pip install stata_kernel
python -m stata_kernel.install

Once you installed it, you might need to configure the path again (if you are using mp version, then you are fine.). Since my stata license is a short-term usage on the SE version, I need to change the stata_path(default is MP version) in configuration file ~/.stata_kernel.conf (use VS code Ctr+Shift+P to find and open it).

[stata_kernel]
stata_path = /usr/local/stata16/stata-se  # change this one 
execution_mode = console
cache_directory = ~/.stata_kernel_cache
autocomplete_closing_symbol = False
graph_format = svg
graph_scale = 0.9  # change this one if you want smaller image 
user_graph_keywords = coefplot,vioplot