Regex tricks with Notepad++ and Statalist

If you haven't heard, the do-file editor in Stata 11 comes with proper syntax highlighting, folding, etc. That means that this post will be obsolete as soon as I upgrade, unless the new do-file editor doesn't do regular expression-based find and replace. No matter. In the meantime, here goes:

People often post code on Statalist and sometimes this code comes from the Stata results window. The difference, as far as code is concerned, is that the command window outputs commands preceded by a dot-blank -- as in . display "hello" instead of display "hello".

Such dot-blanks need to be cleaned up before Stata can run this code. Notepad++ has a regular expression search option. All you have to do is look for ^\. and replace it with nothing. The ^ sign means that you're only looking at the beginning of each line. The backslash escapes the period, which has special meaning in regular expressions. The blank after the dot is optional.

So there. I just did it because I wanted to replicate a neat little simulation.

2 Responses to “Regex tricks with Notepad++ and Statalist”

  1. rafal writes:

    this point is moot too as stata 11 executes commands preceded with a dot so

    . sysuse auto

    is equivalent to

    sysuse auto

    btw, at the moment syntax highlighting is available only under windows.

  2. Gabi Huiber writes:

    Well, there you have it. One more reason to upgrade. Oh, and here's another: Rafal here knows this, but Stata 11, in case that escaped other people's attention, comes with an OS-independent license. So if the newfangled do-file editor under Windows still doesn't cut it for you, feel free to try out your new Stata with one of the supported Unix flavors, paired with something like Emacs.

Leave a Reply