Home > Science > Stata syntax highlighting for gedit

Stata syntax highlighting for gedit

For quite a while, I have been looking for a way to enable Stata syntax highlighting in gedit. Today, I stumbled across this thread:


The second poster (jcress410) wrote a .do file that generates the stata.lang file with the gtksourceview/gedit language specs.

Here’s how to make it work under Ubuntu 10.10:

1. Download the stata lang.zip file & unzip it
2. Change to the unzipped folder and rename file styles to styles.csv
3. Change the value of the working_dir macro in line 9 in the writestatalang.do file to the name of the unzipped directory
4. Run writestatalang.do in Stata
5. Copy the generated stata.lang file to
/usr/share/gtksourceview-2.0/language-specs (for use by all users on the system, requires superuser privileges)
or to
~/.local/share/gtksourceview-2.0/language-specs (for use with your account only)
For the latter option, you may have to create the directory first:

mkdir -p ~/.local/share/gtksourceview-2.0/language-specs

6. Restart gedit.

.do files are now recognized automatically. For manual selection of the Stata Highlight Mode, go to View > Highlight Mode > Scientific > stata

Many thanks to Justin Cress for writing the syntax to generate the file!! You made my day!

Categories: Science
  1. Aldi
    March 14, 2011 at 1:46 pm

    Thank you very much for your manual how to enable gedit to have syntax highlighting with Stata do files. It’s working great! Thank you very much!

  2. Antony Stevens
    March 22, 2011 at 5:00 am

    thank you very much for most helpful advice

  3. Emil Begtrup-Bright
    April 24, 2011 at 6:52 am

    Thanks, this works great! also, when used with the solarized colour scheme for syntax highlightning, it looks beautiful:


  4. October 16, 2011 at 2:43 pm

    made my day, awesome

  5. nixahn
    November 15, 2011 at 7:33 am

    Few comments: the line comment doesn’t work well cause the star is used sometimes for things other than comments. I modified a few things to make it work more to my taste. I also made it so that when I use the comment plugin, only a star is printed without the backslash.

    in the do file, lines 17-19:

    “/* ” ///
    “*/ ” ///
    “* ” ///

    line 85:

    “\*\*|^\*” ///

    this last one says: look for two consecutive stars, or one at the beginning of the line. o.w it is not a comment; if you just want to make it the beginning of the line, it’s

    “^\*” ///

    hope it helps… and thanks to the author;

    • tml
      February 15, 2012 at 8:31 am

      In the interest of making this easier for Windows users, copy the stata.lang file to ProgramFiles (x86)\gedit\share\gtksourceview-2.0.

  6. simon
    December 12, 2012 at 1:38 pm

    This works still handsomely with Ubuntu 12.10.
    The directory for stata.lang is now /usr/share/gtksourceview-3.0/language-specs/

  7. February 19, 2013 at 10:07 am

    Thanks!!! 🙂

  8. Abu Casey
    June 24, 2013 at 4:24 pm

    I followed the steps but gedit doesn’t recognize the new option for syntax highlighting (that is, “Stata” doesn’t show up in my drop-down menu). Any ideas?

    • Maha
      June 13, 2014 at 2:26 pm

      Try copying the stata.lang file in /usr/share/gtksourceview-3.0/language-specs.

  9. maloche
    September 19, 2013 at 5:15 am

    I spent recently some time searching how one can send some Stata code from Gedit to Stata for execution (alternative for Notepad++ under Ubuntu) and for syntax highlighting of Stata commands in Gedit (my current system is Ubuntu 12.04 LTS). Now both issues are resolved (thanks partially to this page) and I attached the archive for anyone who might need it under the following link. All instructions are given in the readme file.

    Enjoy! http://ubuntuforums.org/showthread.php?t=2175462&highlight=stata+gedit

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: