/stata-codespaces

Stata + Jupyter + Codespaces = ❤️ Works well even if you're using Stata version below 17

Primary LanguageJupyter Notebook

Steps

  1. Install Visual Studio Code

  2. Create your codespaces and choose VS Code to open your codespaces

image

  1. Create a Python virtual environment (Python is already pre-installed) and install required packages
sudo apt-get install python3.8-venv
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
python -m stata_kernel.install
jupyter labextension install jupyterlab-stata-highlight
  1. Install Stata for Linux. Follow their instruction on your terminal. You need to input serial number, code, and authorization
  • In tar -zxf /home/you/Downloads/Stata15Linux64.tar.gz part, change /home/you/Downloads/ to your directory
  • In my case, it's /workspaces/stata-codespaces/
% sudo -s
cd /tmp/
mkdir statafiles
cd statafiles
tar -zxf /home/you/Downloads/Stata15Linux64.tar.gz
cd /usr/local
mkdir stata15
cd stata15
/tmp/statafiles/install
  1. After installing Stata, install this Ubuntu package because otherwise it will cause an error when invoking your Stata. Just type yes when you're prompted to
# https://askubuntu.com/questions/895897/error-while-loading-shared-libraries-libpng12-so-0
wget http://archive.ubuntu.com/ubuntu/pool/main/libp/libpng/libpng_1.2.54.orig.tar.xz
tar xvf  libpng_1.2.54.orig.tar.xz 
cd libpng-1.2.54
./autogen.sh
./configure
make -j8 
sudo make install
sudo ldconfig
sudo apt-get install libtool autoconf build-essential pkg-config automake tcsh
  1. Exit from root by typing exit and then you're back to virtual environment

image

  1. Add Stata to your $PATH. Note that if you are using Stata MP, for example, then you need to add change stata15 to stata15-mp; same thing if you're using Stata SE
  • Type nano ~/.bashrc on your terminal, it will prompt you to a Nano text editor
  • Scroll to bottom, and insert the following
# stata path
export PATH="/usr/local/stata15:$PATH"
  • Type source ~/.bashrc
  • You will be exited from the virtual environment, but no worries, just type source .venv/bin/activate
  1. You should by now be able to invoke Stata by typing stata on terminal

image

  1. Almost there! You need to change stata_kernel configuration a little bit typing nano ~/.stata_kernel.conf. Refer to this page on General Settings - stata_path section

image

  1. You're now able to run Stata kernel on Jupyter Notebook using GitHub Codespaces by typing jupyter notebook on terminal. Just click open in browser when you're prompted to. Also, you need to input the token. See the censored the part below, that's the token that you're going to use

image

  1. Create a new file and choose Stata kernel

image

  1. That's it, enjoy!

image

Miscellaneous

  • Let me know if you have any questions by submitting issues here