Introduction

My first Stata was version 10 when Stata’s editor was a plain text editor. Notepad++ was an alternative that allowed code editing features. In version 11, Stata added syntax highlighting. I am now on version 15 and Stata has made significant improvements in the methods (ie. margins, marginsplot) and reproducibility (dyndoc). However, its GUI or the user experience has remained stagnant over the years.

Visual Studio Code was first released in 2015 and it has become a popular code editor for developers. Recent advancements in Visual Studio Code and Windows now allow Stata users to leverage the code editing features of Visual Studio Code to improve their productivity (see examples).

Roadmap

The plan is to run Stata in a Linux terminal so that it can integrate to Visual Studio Code’s terminal. We can do this by enabling Windows Subsystem for Linux, installing Stata-Linux, then connecting Visual Studio Code with the WSL Windows Subsystem for Linux.

We are installing Windows Subsystem for Linux because Stata-Windows only allows GUI mode (Stata-Linux has both GUI and termial mode, Stata-Mac has both GUI and shell mode). Note that Stata-Windows Batch mode does not allow interactively running code.

How-to Guide

Install Windows Subsystem for Linux https://docs.microsoft.com/en-us/windows/wsl/install-win10

In the Microsoft Store, there are several Linux distribution you can choose from. I had success installing Stata on Debian 10 and Ubuntu 18.04. I will describe the installation steps for each.

Debian

Download Debian as your Linux https://www.microsoft.com/store/productId/9MSVKQC78PK6

Run Debian terminal then install Stata-Linux https://www.stata.com/support/faqs/unix/install-download-on-linux/

Right after installing Stata-Linux, if you try running Stata, you will get errors

./stata: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory

./stata: error while loading shared libraries: libpng12.so.0: cannot open shared object file: No such file or directory

To fix these dependency problems, add the wheezy repository to your Debian source list in /etc/apt/source.list

deb http://archive.debian.org/debian/ wheezy main

Then install

sudo apt install libncurses5

sudo apt install libpng12-0

Ubuntu 18.04

Download Ubuntu 18.04 https://www.microsoft.com/en-us/p/ubuntu-1804-lts/9n9tngvndl3q?activetab=pivot:overviewtab

Right after installing Stata-Linux, if you try running Stata, you will get an error

stata: error while loading shared libraries: libpng12.so.0: cannot open shared object file: No such file or directory

To fix these dependency problems, add the xenial repository to your Ubuntu source list in /etc/apt/source.list

deb http://archive.ubuntu.com/ubuntu xenial main

Then install sudo apt install libpng12-0

After installing your choice of Linux

Finally, run Visual Studio Code and connect to Windows Subsystem for Linux https://code.visualstudio.com/docs/remote/wsl

Results

If all goes well, you will have Stata running in Visual Studio Code as below. The code editor is in the left panel. Stata terminal is in the right panel. I am running my code by “run selected text” (shortcut ctrl+enter).

StataVSC