Economics should be open

October 13, 2009

Notepad++ and Stata, a better do file editor

Filed under: Stata — howardchong @ 1:16 am

I do not like the bult in stata editor. It makes reading stata do files a chore. I come a bit from the programming world which will show commented lines and blocks in a different color and highlight reserved words. I looked for al alternative stata text editor / do file editor and like Notepad++.

Notepad++ is a good alternative. You can still run blocks of code (like control-D) and who do file (like control-R) if you set it up. Plus it’s free.

Here’s my simple 3 step setup.

1) Download and install Notepad++

2) To get context highlighting, go here:  download the link to the stata XML file here http://notepad-plus.sourceforge.net/commun/userDefinedLang/userDefineLang_stata.xml .  Click  start, run, type (or paste in) %APPDATA%\Notepad++ then click ok. Assuming you just installed Notepad++, just copy the file you downloaded to this directory, delete the existing userDefineLang.xml and rename your file userDefineLang.xml.

3) To enable running code from Notepad++, follow steps 1-4 of the following page:

http://s281191135.onlinehome.us/2008/20080427-stata.html

It may look complicated, but it is just downloading two files, saving them to c:\ado\personal (or wherever you like), editing two setup files so it knows which stata version you use, and setting up the F9 ad F10 shortcuts.

That’s it.

You’ll get context highlighting, comment block highlighting, and keyword highlighting.

To change the colors of the highlighting, go to View | User Define Dialog

And follow the directions here: http://notepad-plus.sourceforge.net/uk/UserLanguageDefineSystem-HOWTO.php

Advertisements

9 Comments »

  1. 2) To get context highlighting, go here: download the link to the stata XML file here http://notepad-plus.sourceforge.net/commun/userDefinedLang/userDefineLang_stata.xml . Click start, run, type (or paste in) %APPDATA%\Notepad++ then click ok. Assuming you just installed Notepad++, just copy the file you downloaded to this directory, delete the existing userDefineLang.xml and rename your file userDefineLang.xml.

    I didn’t have anything named userDefineLang.xml

    Is that ok?

    Comment by Bill West — October 23, 2009 @ 4:45 pm

    • Yeah, that’s okay. The userDefineLang.xml may not exist. No problem with that.

      Comment by howardchong — February 8, 2010 @ 4:55 am

  2. I am the author of the document mentioned in step 3. Please note that the address of my website has changed. The scripts to integrate Notepad++ with Stata are now available at the following link: http://huebler.blogspot.com/2008/04/stata.html

    Comment by Friedrich Huebler — July 17, 2012 @ 4:17 pm

    • Thanks!

      Comment by howardchong — August 10, 2012 @ 4:29 pm

  3. Hi. Brilliant tutorial. Is there anyway to get Stata to point to the filepath of the .do which you are running lines of code from? As in, when you press f9, stata will look in the directory of the .do file you’re running for saving and using any documents involved in that project. Hope this was clear and again thanks for the tutorial.

    Comment by Ryan — August 10, 2012 @ 10:34 am

    • My method has always been to set a

      global HOME “/mydirectory”

      and then set cd $HOME in the top of the file. This gets changed as I move files across systems.
      I don’t know of a way to dynamically do it so it uses the directory of your do file.

      I know in python you would change your PATH environment. I don’t think stata has a PATH environment. I think it just looks in the local directory, and that may not be where the do file is.

      Do note that if you click on a do file, the local directory is set to the directory of the do file automatically. But if you open stata and then run the do file, I think the pwd is whatever you set as the stata default.

      Comment by howardchong — August 10, 2012 @ 4:29 pm

  4. I don´understand this part of the tutoriual “Click start, run, type (or paste in) %APPDATA%\Notepad++ then click ok” can you help me with that?

    Comment by Nik — April 30, 2014 @ 3:44 pm

    • This is on windows XP.

      For Windows 7 (which I am now on), Click on the START button. Then paste in that text above. It will open a directory with the file explorer.

      For me, it is something like: C:\Users\howard\AppData\Roaming\Notepad++ . The actual directory will differ based on your installation.

      Good luck.

      Comment by howardchong — April 30, 2014 @ 4:34 pm

      • I see. Thank you! Easier than expected 😉

        Comment by Nik — May 2, 2014 @ 7:23 am


RSS feed for comments on this post. TrackBack URI

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: