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).


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). Stata-Windows Batch mode is not useful because it does not allow interactively running code.

How-to Guide

Install Windows Subsystem for Linux

In the Microsoft Store, download Debian as your Linux (I recommend Debian over Ubuntu because I have been unable to get Stata to run on Ubuntu 18 and 20 because of dependency problems)

Run Debian terminal then install Stata-Linux

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

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

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

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

deb []( jessie main

Then install

sudo apt install libncurses5

sudo apt install libpng12-0

Finally, run Visual Studio Code and connect to Windows Subsystem for Linux


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).