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.
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.
Install Windows Subsystem for Linux https://docs.microsoft.com/en-us/windows/wsl/install-win10
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) 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 jessie repository to your Debian source list in
deb [http://archive.debian.org/debian/](http://archive.debian.org/debian/) jessie main
sudo apt install libncurses5
sudo apt install libpng12-0
Finally, run Visual Studio Code and connect to Windows Subsystem for Linux https://code.visualstudio.com/docs/remote/wsl
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).