Monday, July 16, 2007

Fun with Stata: Batch Mode

The other day, Nick tipped me to the fact that you can run Stata in batch mode on Windows (and Macs). At first glance, this didn't seem very useful for me because it's not much of a bother to have the interactive window open. After a little more thought, I wondered if it wouldn't make the program run faster. I have little theoretical basis for why this might be the case (perhaps having to display output sucks up Stata's resources) but I've been rather obsessed with trying to run programs efficiently lately. (Having a program that take days to run will do this to you.)

So I experimented: Run the program in interactive mode. Record time. Repeat for batch mode. 10 trials. To my surprise, the program consistently ran faster in batch mode. The average interactive time was about 1:20 and the average batch time was 1:05. A substantial 15 second (19%) improvement. The next question is to see how results look for longer programs. If you only save fifteen seconds on a ten minute program, it's just not worth it. But if it continues to save 19%, then it just may be. Stay tuned for this experiment.

And, of course, if you're running in batch then you might want make the leap to a fancier text editor like Emacs with the Stata mod. Not fun to get started but it looks like it may pay off in the long-run.

In the meantime, to run a program in batch mode, you just have to:
1. Go to Run.
2. Type "C:\Program Files\Stata9\wstata" /b do "DIRECTORY\PROGRAMNAME.do"

2 comments:

Anonymous said...

Huh?

Jason said...

Stata is the data analysis software that nearly all economists use when they want to do empirical work.