How is Notepad++ better than STATA’s default do-file editor?

Notepad++ does everything that the STATA editor does, and it allows customization. It also comes with productivity enhancing functions like ‘find and replace’, ‘move current line up/down’, ‘block commenting’, ‘record/play macro’, etc. You could also split windows to view two do-files concurrently (right click tab and choose ‘move to other view’), or see one do-file in two split windows (right click tab and choose ‘clone to other view’) to view different sections without scrolling.

Here are some functions that I find useful (see this page for a full list of nice functions and corresponding hot keys):

  • Tab, Shft-Tab: add (without Shft) and remove (with Shft) indentation for current line (or selection). This makes layers of loop easy to read.
  • Ctrl-F/H: find/replace. Its pop-up window also has advanced find/replace options.
  • Ctrl-Shft-Up/Down: move the current line (or selection) up/down. This beats copying and pasting.
  • Ctrl-Shft-U, Ctrl-U: convert current line (or selection) to upper case with Shft, and lower case without Shft.
  • Ctrl-Shft-Q, Ctrl-Q: stream comment current line (or selection) with Shft (wich is /* */ in STATA), and block comment/uncomment without Shft (which is *).
  • Ctrl-Shft-R, Ctrl-Shft-P: start/stop to record macro (with R) and play recorded macro (with P). This set of functions are extremely helpful for repetitive tasks.
  • Ctrl-G: brings a window for you to type in the line number that you want to go to.
  • Ctrl-B: go to matching brace.
    Alt-Left mouse click: column selection instead of row selection.

Bottom line: if you’re a frequent STATA user but not a hardcore programmer (they have Vim and such), coding with Notepad++ will make you more efficient.

Notepad++ and STATA integration:

  1. Download the latest Notepad++ and install it.
  2. Set up hot keys to pass code from Notepad++ to STATA (like Ctrl-D in STATA’s editor).
  3. Set up syntax highlighting: it makes writing do-file more fun and reading it much easier. Below is a snapshot of how it looks. I suggest you download a ready-made syntax file (e.g., this one) and modify it according to your own liking.

Here are the steps:

  • Save the syntax highlighting file in .xml format.
  • In Notepad++, click on ‘Language’ on your toolbar, and select ‘Define your language’. In the pop-up window, click on ‘Import’ and navigate to the directory where you saved the xml file. You should see ‘Import successful’.
  • You can customize all the options to assign colors of your choice to different specifications. Either way, remember to save it and give it a name, say ‘STATA syntax’.
  • Restart Notepad++, and open a do file.
  • Go to the ‘Language’ option and click on ‘STATA syntax’, or whatever name you used.
  • From now on, any do-file you open with Notepad++ will have Stata syntax highlighting. You can also set it as your default do-file editor, if you wish.

You could also setup auto-completion and/or spell-check, but I think they’re a bit of an overkill (still, see Kranker’s page for more details).