Regex tricks with Notepad++ and Statalist
Sunday, 2 August 2009
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.
No. 1 — August 2nd, 2009 at 10:30 pm
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.
No. 2 — August 2nd, 2009 at 11:30 pm
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.