Stata 19 MP: Complete Installation and VS Code Integration

Install Stata 19 MP on an Ubuntu-based desktop, create a desktop launcher, configure VS Code automation with the Stata Enhanced extension, and write cross-platform do-files. Tested on Linux Mint 22.3 Cinnamon (also Zorin OS 18.1 Pro).

Intermediate Verified Working Updated 29 min read Tested on Linux Mint 22.3 Cinnamon (Ubuntu 24.04 Noble base); also tested on Zorin OS 18.1 Pro Hardware Lenovo ThinkPad L14 Gen 2 (Intel i5-1135G7, 16GB RAM, Intel Iris Xe, 1366x768)

Installation, Desktop Integration & VS Code Automation


Who This Guide Is For

This guide is for researchers, economists, and data scientists who:

  • Use Stata as their primary statistical software
  • Have moved to or are considering Linux, especially an Ubuntu-based distribution
  • Want a VS Code workflow similar to what RStudio or Stata’s built-in Do-file Editor offers — run a line, run a chunk, run a whole file — but with the full power of VS Code
  • Want their Linux desktop to look and behave correctly — proper file icons that survive theme switches, taskbar grouping, double-click to open
  • Work with AI coding assistants or LLM agents and want those agents to be able to trigger Stata runs automatically

If you have ever tried to set up Stata on Linux and hit walls with window resizing bugs, blank icons, icons disappearing when the desktop switches between Light and Dark mode, or broken automation scripts — this guide documents every one of those failures and their verified solutions.


What This Guide Achieves

By the end of this guide you will have:

FeatureStatus
Stata 19 MP installed and licensedYes
Stata window resizes correctly (Wayland bug fixed)Yes
Stata taskbar icon groups correctly (no gear icon)Yes
.do, .dta, .smcl files show Stata logo in file managerYes
Icons survive Light Mode → Dark Mode → Auto theme switchYes
Double-click .do or .dta opens in StataYes
Ctrl+Enter in VS Code runs the whole do-file in Stata GUIYes
Shift+Enter in VS Code runs selected line(s) or chunk in Stata GUIYes
Comments, globals, backticks, and all Stata syntax work in selectionYes
Stata launches automatically if not already openYes
Single terminal command runs any do-fileYes
AI agent / LLM mode can trigger Stata runsYes
Complete removal script when neededYes

System Information (Tested Devices and OS Information)

ComponentDetails
MachineLenovo ThinkPad L14 Gen 2
OS (Primary)Linux Mint 22.3 Cinnamon (based on Ubuntu 24.04 Noble)
OS (Secondary)Zorin OS 18.1 (based on Ubuntu 24.04 Noble)
KernelLinux 6.17.0-35-generic x86_64
Desktop (Mint)Cinnamon 6.6.7
Desktop (Zorin)GNOME (zorin:GNOME)
Display ServerX11 (Xorg) — required on both distros
CPU11th Gen Intel Core i5-1135G7 @ 2.40GHz (8 CPUs)
RAM15 GB
Stata EditionStataNow 19 MP
Stata Install Path/usr/local/stata19
VS Code VersionSee VS Code Setup for current version
VS Code Extensionmulti-command by ryuta46
wmctrl1.07
xdotool3.20160805.1
xclip0.13

Known Issues and Why They Happen

Every item in this table was encountered and solved during the making of this guide.

IssueRoot CauseSolution
Stata window cannot be resizedConfirmed Wayland/GTK bug in Stata 18 and 19Force GDK_BACKEND=x11 in .desktop launcher
Do-file Editor shows generic gear iconMissing WM_CLASS mapping in launcherSet StartupWMClass=Xstata-mp in .desktop file
.do/.dta files show blank icons in file managerUser-level MIME overrides in ~/.local may be silently ignoredInject icons system-wide into /usr/share/
Icons disappear when switching between Light and Dark mode (Zorin)Zorin’s sunrise-to-sunset auto theme switch activates a different icon theme (ZorinBlue-Light, Zorin) that has no Stata iconsInject icons into all active theme variants
wmctrl/xdotool do not workThese tools require X11 — they fail silently under WaylandAlways log in on an X11/Xorg session. On Mint it is Xorg or the default session (Mint defaults to X11); on Zorin the label was Zorin on Xorg
Stata flashes open then closes when triggered from VS CodeVS Code fires the paste before Stata has fully initializedAdd sleep 4 after Stata window appears
Selection with backticks or special chars runs in VS Code terminalVS Code shell-expands ${selectedText} before bash runsUse editor.action.clipboardCopyAction — VS Code copies internally
Block comments /* */ show r(199) error when pastedStata command bar does not support do-file syntaxWrite selection to a temp .do file and run with do
Focus stays on Stata after runningNo focus return in original scriptAdded wmctrl -xa code at end of scripts (commented out — user choice)

Prerequisites

1. Log in on Xorg — every single time

At the login screen:

  1. Type your username
  2. Click the gear icon (bottom right of login screen)
  3. Select the X11/Xorg session:
    • Linux Mint: select “Xorg” or “Cinnamon on Xorg” (Mint Cinnamon defaults to X11, so the default session is usually already correct)
    • Zorin OS: the exact label was “Zorin on Xorg”
  4. Enter your password

Confirm after login:

echo $XDG_SESSION_TYPE
# Must print: x11

Warning: If this prints wayland — log out and repeat. Every tool in this guide (wmctrl, xdotool, xclip) requires X11. It may not work properly on Wayland.

2. Have your Stata installer ready

Your installer file should be at:

~/Downloads/StataNow19Linux64.tar.gz

3. Have your Stata license details ready

You will need:

  • Serial number
  • Code
  • Authorization
  • Name and Affiliation

Part 1 — Install Required System Tools

sudo apt update
sudo apt install wmctrl xdotool xclip \
  libcanberra-gtk-module libcanberra-gtk3-module
ToolPurpose
wmctrlIdentify and focus X11 windows by class name
xdotoolSimulate keyboard input (Ctrl+V, Return)
xclipRead and write the X11 clipboard
libcanberra-gtk-moduleGTK event library Stata depends on at startup
libcanberra-gtk3-moduleGTK3 variant of the above

Part 2 — Install Stata 19 MP

# 1. Extract the installer as your normal user (no root needed)
cd /tmp
mkdir -p statafiles
tar -xvzf ~/Downloads/StataNow19Linux64.tar.gz -C /tmp/statafiles

# 2. Become root for the installation steps
sudo -s

# 3. Create the installation directory and run the installer
mkdir -p /usr/local/stata19
cd /usr/local/stata19
/tmp/statafiles/install
# Press 'y' when prompted

# 4. Initialize the license
./stinit
# Enter when prompted:
#   - Serial number
#   - Code
#   - Authorization
#   - Name
#   - Affiliation

# 5. Exit root
exit

Verify the installation

ls /usr/local/stata19/xstata-mp
# Should return the file path — not "No such file or directory"

Warning: Stata is installed as root but must always be run as your normal desktop user. Running Stata as root breaks clipboard access and the entire automation workflow.


Part 3 — Fix Wayland Resizing Bug and Taskbar Grouping

Create a custom application launcher that:

  • Forces Stata to use the X11 backend (GDK_BACKEND=x11) — fixes the resize bug
  • Accepts file arguments (%F) — double-clicking .do/.dta opens them in Stata
  • Groups all Stata windows under one taskbar icon — fixes the gear icon problem
nano ~/.local/share/applications/stata.desktop

Paste exactly:

[Desktop Entry]
Version=1.0
Terminal=false
Type=Application
Name=Stata 19 MP
Comment=Stata Statistical Software
Exec=env GDK_BACKEND=x11 /usr/local/stata19/xstata-mp %F
Icon=/usr/local/stata19/stata19.png
Categories=Education;Science;Math;
StartupNotify=true
StartupWMClass=Xstata-mp
MimeType=application/x-stata-dta;application/x-stata-dtas;application/x-stata-do;application/x-stata-ado;application/x-stata-smcl;application/x-stata-stpr;application/x-stata-gph;application/x-stata-sthlp;application/x-stata-mata;application/x-stata-ster;application/x-stata-stsem;

Save, make executable, update database:

chmod +x ~/.local/share/applications/stata.desktop
update-desktop-database ~/.local/share/applications

What each key line does

LinePurpose
Exec=env GDK_BACKEND=x11 ...Forces X11 backend — fixes the Wayland resize bug
%FPasses double-clicked file paths as arguments to Stata
StartupWMClass=Xstata-mpGroups the Do-file Editor under the Stata taskbar icon
MimeType=...Registers all Stata file types to open with this launcher

Warning: Do not use third-party Stata integration scripts after this step. Scripts like dirtyhawk/stata-integration overwrite this file and bring the Wayland resize bug back.


Part 4 — Fix Blank File Icons (Light Mode, Dark Mode and Auto-Switch)

Why icons disappear on theme switch

Linux Mint does not have an automatic theme switcher — you manually pick one icon theme. However, you should still inject into hicolor (the universal fallback theme) and your active Mint-Y variant so icons survive if you ever switch themes.

Zorin OS 18 includes a sunrise-to-sunset automatic theme switcher. At sunrise it activates Light Mode (ZorinBlue-Light / Zorin icon themes). At sunset it activates Dark Mode (ZorinBlue-Dark). If you only inject icons into the Dark theme, they vanish every morning when the desktop switches to Light. The fix is to inject into all active theme variants at once.

User-level MIME and icon overrides in ~/.local/share/ may be silently ignored on both distros. Everything must go into /usr/share/.

Detect your distro and icon theme

Before injecting, identify what you’re working with:

# Check your distro
cat /etc/os-release | grep -E "^ID="
# Mint: ID=linuxmint
# Zorin: ID=zorin

# Check your active icon theme
# Mint (Cinnamon):
gsettings get org.cinnamon.desktop.interface icon-theme
# Zorin (GNOME):
gsettings get org.gnome.desktop.interface icon-theme

Block 1 — Create the global MIME configuration

sudo tee /usr/share/mime/packages/stata-system.xml > /dev/null <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
  <mime-type type="application/x-stata-dta">
    <comment>Stata Data File</comment>
    <glob pattern="*.dta"/>
    <icon name="application-x-stata-dta"/>
  </mime-type>
  <mime-type type="application/x-stata-dtas">
    <comment>Stata Data File</comment>
    <glob pattern="*.dtas"/>
    <icon name="application-x-stata-dtas"/>
  </mime-type>
  <mime-type type="application/x-stata-do">
    <comment>Stata Do-File</comment>
    <glob pattern="*.do"/>
    <icon name="application-x-stata-do"/>
  </mime-type>
  <mime-type type="application/x-stata-ado">
    <comment>Stata Ado-File</comment>
    <glob pattern="*.ado"/>
    <icon name="application-x-stata-ado"/>
  </mime-type>
  <mime-type type="application/x-stata-smcl">
    <comment>Stata Log File</comment>
    <glob pattern="*.smcl"/>
    <icon name="application-x-stata-smcl"/>
  </mime-type>
  <mime-type type="application/x-stata-stpr">
    <comment>Stata Project</comment>
    <glob pattern="*.stpr"/>
    <icon name="application-x-stata-stpr"/>
  </mime-type>
  <mime-type type="application/x-stata-gph">
    <comment>Stata Graph</comment>
    <glob pattern="*.gph"/>
    <icon name="application-x-stata-gph"/>
  </mime-type>
</mime-info>
EOF

Block 2 — Inject icons into your distro’s theme variants

For Linux Mint (covers hicolor + your active Mint-Y theme):

# First, find your active icon theme
ICON_THEME=$(gsettings get org.cinnamon.desktop.interface icon-theme | tr -d "'")
echo "Active icon theme: $ICON_THEME"

# Create directories for hicolor (universal fallback) and your active theme
sudo mkdir -p /usr/share/icons/hicolor/{48x48,64x64,256x256,scalable}/mimetypes/
sudo mkdir -p "/usr/share/icons/$ICON_THEME"/{48x48,64x64,256x256,scalable}/mimetypes/

# Inject Stata icon for every file extension into both themes and every size
for ext in dta dtas do ado smcl stpr gph; do
    for size in 48x48 64x64 256x256 scalable; do
        sudo cp /usr/local/stata19/stata19.png \
          "/usr/share/icons/hicolor/$size/mimetypes/application-x-stata-$ext.png"
        sudo cp /usr/local/stata19/stata19.png \
          "/usr/share/icons/$ICON_THEME/$size/mimetypes/application-x-stata-$ext.png"
    done
done

# Optional: also inject into other Mint-Y variants you might switch to
for theme in Mint-Y Mint-Y-Aqua Mint-Y-Dark Mint-Y-Blue Mint-Y-Grey Mint-Y-Orange Mint-Y-Pink Mint-Y-Purple Mint-Y-Red Mint-Y-Teal Mint-Y-Sand Mint-Y-Cyan Mint-Y-Navy Mint-Y-Yaru; do
    if [[ -d "/usr/share/icons/$theme" ]]; then
        for ext in dta dtas do ado smcl stpr gph; do
            for size in 48x48 64x64 256x256 scalable; do
                sudo mkdir -p "/usr/share/icons/$theme/$size/mimetypes/"
                sudo cp /usr/local/stata19/stata19.png \
                  "/usr/share/icons/$theme/$size/mimetypes/application-x-stata-$ext.png"
            done
        done
    fi
done

For Zorin OS (covers Light Mode, Dark Mode, and the auto-switch between them):

# Create all required directories across all four Zorin theme variants
sudo mkdir -p /usr/share/icons/hicolor/{48x48,64x64,256x256,scalable}/mimetypes/
sudo mkdir -p /usr/share/icons/ZorinBlue-Dark/{48x48,64x64,256x256,scalable}/mimetypes/
sudo mkdir -p /usr/share/icons/ZorinBlue-Light/{48x48,64x64,256x256,scalable}/mimetypes/
sudo mkdir -p /usr/share/icons/Zorin/{48x48,64x64,256x256,scalable}/mimetypes/

# Inject Stata icon for every file extension into every theme and every size
for ext in dta dtas do ado smcl stpr gph; do
    for size in 48x48 64x64 256x256 scalable; do
        sudo cp /usr/local/stata19/stata19.png \
          "/usr/share/icons/hicolor/$size/mimetypes/application-x-stata-$ext.png"
        sudo cp /usr/local/stata19/stata19.png \
          "/usr/share/icons/ZorinBlue-Dark/$size/mimetypes/application-x-stata-$ext.png"
        sudo cp /usr/local/stata19/stata19.png \
          "/usr/share/icons/ZorinBlue-Light/$size/mimetypes/application-x-stata-$ext.png"
        sudo cp /usr/local/stata19/stata19.png \
          "/usr/share/icons/Zorin/$size/mimetypes/application-x-stata-$ext.png"
    done
done

Block 3 — Rebuild all caches and force reload

For Linux Mint:

# Rebuild MIME database
sudo update-mime-database /usr/share/mime

# Refresh icon caches for hicolor and your active theme
ICON_THEME=$(gsettings get org.cinnamon.desktop.interface icon-theme | tr -d "'")
sudo gtk-update-icon-cache -f -t /usr/share/icons/hicolor
sudo gtk-update-icon-cache -f -t "/usr/share/icons/$ICON_THEME"

# Also refresh other Mint-Y variants if you injected into them
for theme in Mint-Y Mint-Y-Aqua Mint-Y-Dark Mint-Y-Blue Mint-Y-Grey Mint-Y-Orange Mint-Y-Pink Mint-Y-Purple Mint-Y-Red Mint-Y-Teal Mint-Y-Sand Mint-Y-Cyan Mint-Y-Navy Mint-Y-Yaru; do
    if [[ -d "/usr/share/icons/$theme" ]]; then
        sudo gtk-update-icon-cache -f -t "/usr/share/icons/$theme"
    fi
done

# Wipe thumbnail cache to force visual update
rm -rf ~/.cache/thumbnails/*

# Restart file manager (Nemo)
nemo -q

For Zorin OS:

# Rebuild MIME database
sudo update-mime-database /usr/share/mime

# Refresh icon caches for all four Zorin theme variants
sudo gtk-update-icon-cache -f -t /usr/share/icons/hicolor
sudo gtk-update-icon-cache -f -t /usr/share/icons/ZorinBlue-Dark
sudo gtk-update-icon-cache -f -t /usr/share/icons/ZorinBlue-Light
sudo gtk-update-icon-cache -f -t /usr/share/icons/Zorin

# Wipe thumbnail cache to force visual update
rm -rf ~/.cache/thumbnails/*

# Restart file manager (Nautilus)
nautilus -q

Your .do, .dta, and other Stata files now show the Stata logo in the file manager — through manual theme switches (Mint) or automatic theme transitions (Zorin).


Part 5 — VS Code Integration (Run Whole Do-File)

Step 1 — Create the do-file runner script

mkdir -p ~/.local/bin
nano ~/.local/bin/stata_run_do.sh

Paste:

#!/usr/bin/env bash
set -euo pipefail

STATA_BIN="/usr/local/stata19/xstata-mp"
STATA_WMCLASS="Xstata-mp"
EDITOR_WMCLASS="code"

DOFILE="${1:-}"
if [[ -z "$DOFILE" ]]; then
  echo "Usage: stata_run_do.sh /full/path/to/file.do" >&2
  exit 2
fi

# Make path absolute and resolve symlinks
DOFILE="$(readlink -f "$DOFILE")"

# Verify file exists
if [[ ! -f "$DOFILE" ]]; then
  echo "Error: File not found: $DOFILE" >&2
  exit 1
fi

# Put the Stata do command on clipboard — quoted to preserve spaces
printf 'do "%s"\n' "$DOFILE" | xclip -selection clipboard

# Launch Stata GUI if not already running
if ! wmctrl -x -l | grep -qi "${STATA_WMCLASS}"; then
  "${STATA_BIN}" >/dev/null 2>&1 &
  for i in {1..50}; do
    wmctrl -x -l | grep -qi "${STATA_WMCLASS}" && break
    sleep 0.2
  done
  sleep 4
fi

# Focus Stata, paste and run
wmctrl -xa "${STATA_WMCLASS}"
sleep 0.3
xdotool key --clearmodifiers ctrl+v Return

# Return focus to editor (uncomment below to enable)
# sleep 0.5
# wmctrl -xa "${EDITOR_WMCLASS}"

Make executable:

chmod +x ~/.local/bin/stata_run_do.sh

Step 2 — Add to PATH (one time only)

echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Verify:

which stata_run_do.sh
# Should print: /home/mohsin/.local/bin/stata_run_do.sh

Part 6 — VS Code Integration (Run Selected Lines or Chunks)

Why a simple approach does not work

VS Code tasks pass ${selectedText} as a shell argument. Bash receives your Stata code and tries to execute it as shell commands. Stata code contains:

  • Backticks: `c(os)' → bash interprets as command substitution
  • Block comments: /* ... */ → bash sees as invalid syntax
  • Plain text comment lines → bash tries to run them as commands

Additionally, even if you get the text to a script safely, pasting raw code directly into Stata’s command bar fails because Stata’s command bar is not a do-file. It executes one command at a time and does not support block comments or multi-line syntax. Every comment line produces r(199).

The correct solution

  1. Use the multi-command extension to copy selection internally in VS Code (no shell involved)
  2. Write clipboard contents to a temp .do file using xclip (no shell interpretation)
  3. Send do "/tmp/stata_selection_run.do" to Stata — a proper do-file run, not a paste

Step 1 — Install the multi-command extension

In VS Code:

  1. Press Ctrl+Shift+X
  2. Search: ryuta46.multi-command
  3. Install “multi-command” by ryuta46

Step 2 — Create the selection runner script

nano ~/.local/bin/stata_run_selection.sh

Paste:

#!/usr/bin/env bash
set -euo pipefail

STATA_BIN="/usr/local/stata19/xstata-mp"
STATA_WMCLASS="Xstata-mp"
EDITOR_WMCLASS="code"

# Fixed temp do-file location — reused every run
TMPDO="/tmp/stata_selection_run.do"

# Read selected code from clipboard and write to temp do-file
# xclip reads clipboard directly — no shell interpretation of contents
xclip -selection clipboard -o > "$TMPDO"

# Verify something was written
if [[ ! -s "$TMPDO" ]]; then
  echo "Clipboard is empty — nothing selected to run" >&2
  exit 1
fi

# Launch Stata GUI if not already running
if ! wmctrl -x -l | grep -qi "${STATA_WMCLASS}"; then
  "${STATA_BIN}" >/dev/null 2>&1 &
  for i in {1..50}; do
    wmctrl -x -l | grep -qi "${STATA_WMCLASS}" && break
    sleep 0.2
  done
  # Wait for Stata to fully initialize
  sleep 4
fi

# Put the do command on the clipboard — not the raw code
printf 'do "%s"\n' "$TMPDO" | xclip -selection clipboard

# Focus Stata and run
wmctrl -xa "${STATA_WMCLASS}"
sleep 0.3
xdotool key --clearmodifiers ctrl+v Return

# Return focus to VS Code (uncomment below to enable)
# sleep 0.5
# wmctrl -xa "${EDITOR_WMCLASS}"

Make executable:

chmod +x ~/.local/bin/stata_run_selection.sh

Step 3 — Create .vscode/tasks.json

In your project folder create .vscode/tasks.json:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Run do-file in Stata GUI",
      "type": "shell",
      "command": "${env:HOME}/.local/bin/stata_run_do.sh",
      "args": ["${file}"],
      "problemMatcher": [],
      "presentation": {
        "reveal": "silent",
        "panel": "shared"
      }
    },
    {
      "label": "Run selection in Stata GUI",
      "type": "shell",
      "command": "${env:HOME}/.local/bin/stata_run_selection.sh",
      "args": [],
      "problemMatcher": [],
      "presentation": {
        "reveal": "silent",
        "panel": "shared"
      }
    }
  ]
}

Step 4 — Set keybindings

Open ~/.config/Code/User/keybindings.json:

[
  {
    "key": "ctrl+enter",
    "command": "workbench.action.tasks.runTask",
    "args": "Run do-file in Stata GUI"
  },
  {
    "key": "shift+enter",
    "command": "extension.multiCommand.execute",
    "args": {
      "sequence": [
        "editor.action.clipboardCopyAction",
        {
          "command": "workbench.action.tasks.runTask",
          "args": "Run selection in Stata GUI"
        }
      ]
    },
    "when": "editorTextFocus"
  }
]

Step 5 — Keep settings.json clean

~/.config/Code/User/settings.json must have no stata.* keys:

{
}

How to use it

ActionSteps
Run a single linePlace cursor on line → Ctrl+L to select → Shift+Enter
Run a selected chunkHighlight any block of Stata code → Shift+Enter
Run the whole fileCtrl+Enter — no selection needed

How it works end to end

Shift+Enter pressed
  └─→ multi-command fires two actions in sequence:
        1. editor.action.clipboardCopyAction
             └─→ VS Code copies selected text to X11 clipboard
                 INTERNALLY — bash never sees the text
        2. Run selection in Stata GUI task
             └─→ stata_run_selection.sh runs
                   ├─→ xclip reads clipboard → writes raw bytes
                   │   to /tmp/stata_selection_run.do
                   ├─→ puts  do "/tmp/stata_selection_run.do"
                   │   on clipboard
                   ├─→ focuses Stata GUI
                   ├─→ pastes + Enter
                   │     └─→ Stata runs the temp do-file
                   │           Comments      Supported
                   │           Globals       Supported
                   │           Backticks     Supported
                   │           Block comments Supported
                   │           Macros        Supported
                   └─→ focus stays on Stata
                       (or returns to VS Code if uncommented)

Part 7 — Running Do-Files from Terminal or AI Agent

The same stata_run_do.sh script works in all contexts — terminal, VS Code, and AI agent.

Syntax

stata_run_do.sh /full/path/to/yourfile.do

Real example

stata_run_do.sh /media/mohsin/mmh/Github/STATA_codes_contribution/Stata/dofile_boilerplot_all_platform.do

For AI agents and automated scripts

Use the full absolute path — AI agents and non-interactive shells do not expand ~:

/home/mohsin/.local/bin/stata_run_do.sh /media/mohsin/mmh/Github/STATA_codes_contribution/Stata/dofile_boilerplot_all_platform.do

Usage across all contexts

ContextCommand
Terminal (short)stata_run_do.sh /path/to/file.do
Terminal (full path)/home/mohsin/.local/bin/stata_run_do.sh /path/to/file.do
VS Code whole fileCtrl+Enter
VS Code selectionHighlight code → Shift+Enter
AI Agent / LLM mode/home/mohsin/.local/bin/stata_run_do.sh /path/to/file.do

Part 8 — Complete Removal (Scorched Earth)

Use this for a completely clean reinstall. This script does not touch ~/mmh, ~/Downloads, GitHub repositories, or any personal project data.

Phase 1 — Remove core application and system integrations

# Remove the main Stata installation
sudo rm -rf /usr/local/stata*
sudo rm -f /usr/local/bin/stata*
sudo rm -f /usr/local/bin/xstata*

# Remove system-wide desktop shortcuts and MIME XML
sudo rm -f /usr/share/applications/*stata*.desktop
sudo rm -f /usr/share/mime/packages/*stata*.xml

# Remove Stata icons from all theme variants
sudo find /usr/share/icons/hicolor -name "application-x-stata-*.png" -delete
# Mint themes (all Mint-Y variants):
for theme in Mint-Y Mint-Y-Aqua Mint-Y-Dark Mint-Y-Blue Mint-Y-Grey Mint-Y-Orange Mint-Y-Pink Mint-Y-Purple Mint-Y-Red Mint-Y-Teal Mint-Y-Sand Mint-Y-Cyan Mint-Y-Navy Mint-Y-Yaru Mint-X Mint-X-Aqua; do
    sudo find "/usr/share/icons/$theme" -name "application-x-stata-*.png" -delete 2>/dev/null
done
# Zorin themes:
sudo find /usr/share/icons/ZorinBlue-Dark -name "application-x-stata-*.png" -delete 2>/dev/null
sudo find /usr/share/icons/ZorinBlue-Light -name "application-x-stata-*.png" -delete 2>/dev/null
sudo find /usr/share/icons/Zorin -name "application-x-stata-*.png" -delete 2>/dev/null
sudo find /usr/share/icons -name "stata19*.png" -delete

# Rebuild system caches
sudo update-mime-database /usr/share/mime
sudo gtk-update-icon-cache -f -t /usr/share/icons/hicolor
for theme in Mint-Y Mint-Y-Aqua Mint-Y-Dark Mint-Y-Blue Mint-Y-Grey Mint-Y-Orange Mint-Y-Pink Mint-Y-Purple Mint-Y-Red Mint-Y-Teal Mint-Y-Sand Mint-Y-Cyan Mint-Y-Navy Mint-Y-Yaru Mint-X Mint-X-Aqua; do
    sudo gtk-update-icon-cache -f -t "/usr/share/icons/$theme" 2>/dev/null
done
sudo gtk-update-icon-cache -f -t /usr/share/icons/ZorinBlue-Dark 2>/dev/null
sudo gtk-update-icon-cache -f -t /usr/share/icons/ZorinBlue-Light 2>/dev/null
sudo gtk-update-icon-cache -f -t /usr/share/icons/Zorin 2>/dev/null

Phase 2 — Clean user-level caches and leftovers

# Remove user-level Stata preferences and state
rm -rf ~/.stata*
rm -rf ~/.config/Stata*
rm -rf ~/.local/share/Stata*
rm -rf ~/.cache/Stata*

# Remove user desktop shortcuts and MIME rules
rm -f ~/.local/share/applications/*stata*.desktop
rm -f ~/.local/share/mime/packages/*stata*.xml

# Remove Jupyter / Python kernel linkages (nbstata)
rm -rf ~/.local/share/jupyter/kernels/nbstata

# Remove VS Code helper scripts
rm -f ~/.local/bin/stata_run_do.sh
rm -f ~/.local/bin/stata_run_selection.sh

# Remove temp files
sudo rm -rf /tmp/stata*
rm -f /tmp/stata_selection_run.do

# Clear thumbnail cache
rm -rf ~/.cache/thumbnails/*

# Rebuild local user databases
update-desktop-database ~/.local/share/applications
update-mime-database ~/.local/share/mime

Phase 3 — Clean terminal PATH and restart

# Remove any stata lines from bash config
sed -i '/stata/d' ~/.bashrc

# Reload bash profile
source ~/.bashrc

# Restart file manager
# Linux Mint:
nemo -q
# Zorin OS:
nautilus -q

After all three phases the system is a clean slate. Restart from Part 1.


Daily Usage

StepAction
1Log in → gear icon → your X11/Xorg session (labeled Xorg or Cinnamon on Xorg on Mint — Mint defaults to X11; Zorin on Xorg on Zorin OS)
2Open Stata GUI manually (first time each session)
3Open VS Code and your .do file
4Ctrl+Enter — run whole file in Stata GUI
5Highlight any code → Shift+Enter — run selection in Stata GUI

Tip: Once Stata is open, leave it open for your entire working session. The scripts detect it is already running and skip the launch step on every subsequent run.


Keybinding Reference

KeybindingAction
Ctrl+EnterRun the entire currently open .do file in Stata GUI
Shift+EnterRun the currently selected line(s) or chunk in Stata GUI
Ctrl+LSelect the entire current line (use before Shift+Enter for a single line)
Ctrl+Shift+XOpen VS Code Extensions (to install multi-command)
Ctrl+Shift+PVS Code command palette (use to reload window after config changes)

File Locations Reference

FilePath
Stata binary/usr/local/stata19/xstata-mp
Stata icon/usr/local/stata19/stata19.png
Stata license/usr/local/stata19/stata.lic
App launcher~/.local/share/applications/stata.desktop
System MIME rules/usr/share/mime/packages/stata-system.xml
Do-file runner script~/.local/bin/stata_run_do.sh
Selection runner script~/.local/bin/stata_run_selection.sh
Selection temp do-file/tmp/stata_selection_run.do
VS Code task file~/.config/Code/User/tasks.json
VS Code keybindings~/.config/Code/User/keybindings.json
VS Code settings~/.config/Code/User/settings.json

Troubleshooting Reference

ProblemCauseFix
Window cannot be resizedWayland bugConfirm GDK_BACKEND=x11 is in .desktop file
Generic gear icon in taskbarWrong WM_CLASSSee WM_CLASS section below
Blank file icons in file managerUser-level MIME ignoredRe-run Part 4 entirely
Icons disappear after theme switchLight mode theme has no Stata iconsRe-run Part 4 Block 2 — covers all theme variants
Stata flashes open then closesStata not fully initializedConfirm sleep 4 is in the launch block of both scripts
Ctrl+Enter does nothingKeybinding not savedCtrl+Shift+P → Reload Window, recheck keybindings.json
Shift+Enter runs code in VS Code terminalWrong keybinding — using runSelectedTextConfirm multi-command extension is installed and keybinding uses extension.multiCommand.execute
Shift+Enter does nothingmulti-command not installedInstall ryuta46.multi-command from VS Code Extensions
Block comments give r(199) errorRaw code pasted into Stata command barConfirm script uses do "/tmp/stata_selection_run.do" not direct paste
Backticks or globals fail in selectionShell expanding clipboard contentsConfirm script uses xclip -selection clipboard -o > "$TMPDO"
Paste does not reach StataTiming issueIncrease sleep 0.3 to sleep 0.5 in both scripts
Stata takes too long to startSlow bootIncrease sleep 4 to sleep 6 in both scripts
Focus returns to VS Code unwantedFocus return lines activeComment out the last two lines in both scripts
Focus does not return to VS CodeFocus return lines commented outUncomment the last two lines in both scripts
wmctrl/xdotool/xclip not foundNot installedsudo apt install wmctrl xdotool xclip
Nothing happens on Ctrl+EnterScript errorTest manually: stata_run_do.sh /path/to/file.do
Session is WaylandWrong loginLog out → gear icon → your X11/Xorg session (called Xorg or Cinnamon on Xorg on Mint — Mint defaults to X11; Zorin on Xorg on Zorin OS)
~ not expanding in AI agentNon-interactive shellUse /home/mohsin/ instead of ~/

Finding WM_CLASS (if taskbar grouping breaks after a Stata update)

xprop WM_CLASS
# Cursor becomes crosshair — click the Stata window
#
# Example output:
# WM_CLASS(STRING) = "xstata-mp", "Xstata-mp"
#                                  ^^^^^^^^^^^
#                    Use this SECOND string

Update your launcher:

nano ~/.local/share/applications/stata.desktop
# Edit the line: StartupWMClass=Xstata-mp
# Replace with whatever the second string was

update-desktop-database ~/.local/share/applications

FAQ

Q: Do I have to open Stata manually before pressing Ctrl+Enter or Shift+Enter? A: For the first run in a session — yes. The scripts can launch Stata automatically, but there is a timing gap: Stata needs about 4 seconds to fully initialize before it can accept commands. In practice it is most reliable to open Stata once at the start of your working session and leave it open. Every subsequent Ctrl+Enter or Shift+Enter is instant.


Q: Why does the script use sleep 4 when Stata launches? A: The wmctrl -x -l command detects when the Stata window appears, but the window appearing does not mean Stata is ready to accept commands. Stata needs additional time to load its libraries and initialize the command input. The sleep 4 covers that gap. On a fast machine you may reduce this to sleep 2.


Q: Why do I need the multi-command extension? A: The selection workflow requires two actions in sequence: (1) copy the selection internally in VS Code, then (2) trigger the task. VS Code keybindings natively support only one command per binding. The multi-command extension chains them together. It is small, free, and has no side effects on the rest of VS Code.


Q: Why does Shift+Enter run a temp .do file instead of pasting directly? A: Stata’s command bar and a do-file are fundamentally different execution contexts. The command bar runs one command at a time and does not support block comments /* */, multi-line constructs, or plain text lines. Pasting code directly results in r(199) errors on every comment. Writing to a temp .do file and running it with do gives Stata the full do-file execution context where all syntax is valid.


Q: Why do my file icons disappear when my desktop switches to Light Mode? A: Linux Mint does not have an automatic theme switcher, but you should still inject into hicolor and your active Mint-Y theme so icons survive manual theme changes. Zorin OS 18 has a sunrise-to-sunset automatic theme switcher. At sunrise it activates ZorinBlue-Light and Zorin icon themes. If you only injected icons into ZorinBlue-Dark, they do not exist in the Light theme and your file manager shows blank pages. The fix in Part 4 injects into all active theme variants so icons survive every transition.


Q: Is the temp file /tmp/stata_selection_run.do safe? A: Yes. /tmp is cleared on every reboot. The file is overwritten on every Shift+Enter press. It contains only the code you just selected. No sensitive data is stored persistently.


Q: Can I run selections that are hundreds of lines long? A: Yes. The temp file approach has no length limit. Earlier approaches that passed ${selectedText} as a shell argument had limits, but writing to a file bypasses that entirely.


Q: Can I use this from an AI coding assistant like GitHub Copilot agent mode? A: Yes. The terminal command stata_run_do.sh /path/to/file.do works from any context including AI agent mode. For agents, always use the full path /home/mohsin/.local/bin/stata_run_do.sh since non-interactive shells may not load your ~/.bashrc PATH.


Q: Will this break after a Stata update? A: Most likely not. The only thing that could change is StartupWMClass if StataCorp changes the internal window class name. If the gear icon returns after an update, run xprop WM_CLASS, click the Stata window, and update the value in stata.desktop. Everything else is independent of Stata’s version.


Q: Does this work with Stata SE or Stata IC? A: Yes. See Adapting This Guide for Other Systems. Replace xstata-mp with xstata-se or xstata throughout all scripts and the .desktop file.


Q: Do I need to redo the VS Code setup for every new project? A: Only the .vscode/tasks.json file is project-specific. The scripts, keybindings, and PATH setup are global and work for every project automatically. You can also copy the .vscode/ folder from one project to another.


Q: The window switching feels laggy. Can I reduce it? A: Yes. Disable desktop window animations:

Linux Mint (Cinnamon):

gsettings set org.cinnamon.desktop.interface enable-animations false

Re-enable with:

gsettings set org.cinnamon.desktop.interface enable-animations true

Or use the GUI: System Settings → Effects → toggle off all animations.

Zorin OS (GNOME):

gsettings set org.gnome.desktop.interface enable-animations false

Re-enable with:

gsettings set org.gnome.desktop.interface enable-animations true

Q: Can I put Stata on a separate workspace so I never see the window switch? A: Yes. Open Stata, right-click its taskbar icon → Move to Workspace 2. The scripts focus it invisibly, paste the command, and return. You only switch to workspace 2 manually when you want to read output.


Q: After running, should focus stay on Stata or return to VS Code? A: This is a personal preference. Both scripts have the focus-return lines commented out by default — meaning focus stays on Stata after running so you can immediately see output. To return focus to VS Code automatically after every run, uncomment these two lines at the bottom of both scripts:

# sleep 0.5
# wmctrl -xa "${EDITOR_WMCLASS}"

Quick Verification Checklist

Run these after a fresh install to confirm everything is working:

# 1. Confirm Xorg session
echo $XDG_SESSION_TYPE
# Expected: x11

# 2. Confirm Stata binary exists
ls /usr/local/stata19/xstata-mp
# Expected: file path returned

# 3. Confirm both scripts are on PATH
which stata_run_do.sh
# Expected: /home/mohsin/.local/bin/stata_run_do.sh

which stata_run_selection.sh
# Expected: /home/mohsin/.local/bin/stata_run_selection.sh

# 4. Confirm multi-command extension is installed
code --list-extensions | grep ryuta46
# Expected: ryuta46.multi-command

# 5. Test run a whole do-file from terminal
stata_run_do.sh /path/to/yourfile.do
# Expected: Stata opens and runs the file

# 6. Test selection from VS Code
# Open a .do file, select lines including block comments, press Shift+Enter
# Expected: runs correctly in Stata with no r(199) errors

# 7. Switch to a different icon theme and check file manager
# Linux Mint: System Settings → Themes → Icons → pick a different Mint-Y variant
# Zorin OS: change theme in Settings → Appearance
# Expected: .do and .dta files still show the Stata logo icon

All seven passing means everything is correctly configured including the theme switch fix.


Adapting This Guide for Other Systems

ItemWhere to change
Stata SE → replace xstata-mp with xstata-seBoth scripts + .desktop file
Stata IC → replace xstata-mp with xstataBoth scripts + .desktop file
StartupWMClass value changedUse xprop WM_CLASS to find correct value
Username mohsinReplace with your Linux username in all full paths
Icon theme not Zorin or MintRun ls /usr/share/icons/ — add your theme dirs to Part 4 Block 2
Linux Mint (Cinnamon)Use gsettings get org.cinnamon.desktop.interface icon-theme; restart file manager with nemo -q; Mint defaults to X11
Zorin OS (GNOME)Use gsettings get org.gnome.desktop.interface icon-theme; restart file manager with nautilus -q
Ubuntu 22.04 / 24.04 (GNOME)All steps apply — no sunrise/sunset switcher so only hicolor needed in Part 4
Other Debian-based distroAll steps apply — identify your active icon theme and add it to Part 4; identify your file manager for the restart command
Slow machineIncrease sleep 4 to sleep 6 in both scripts
Fast machineDecrease sleep 4 to sleep 2 and test

Acknowledgements

This guide was built through a real troubleshooting session on real hardware. Every bug in the Known Issues section was actually encountered. Every solution was actually tested. Nothing here is theoretical.

Special thanks to the developers of:

  • wmctrl — X11 window control
  • xdotool — X11 keyboard and mouse automation
  • xclip — X11 clipboard interface
  • multi-command by ryuta46 — VS Code sequential command execution

Tested on Linux Mint 22.3 Cinnamon (also Zorin OS 18.1 Pro) · ThinkPad L14 Gen 2 (i5-1135G7, 16GB, Iris Xe) · April–May 2026 This guide is free to share, adapt, and republish with attribution. If you face any issue or problem regarding this, take help from an LLM using this guide, and comment below your problem or solution — whatever you want to share.

Discussion