Wednesday, November 28, 2007

Step 2: Setting up a profile.do file

One thing you'll find in your "Getting Started in Stata" manual is a brief explanation of setting up a profile.do file. Briefly, this is a file that's run every time Stata is started. So if you always want to perform certain actions - start a log, set the memory, change the working directory - this is the place to do it.

There are three steps to setting a profile.do file:

  1. Write a do-file
  2. Save it in the appropriate location (more on this in a moment)
  3. Restart Stata and check to Results window


To write a do-file in Stata's built-in editor, go to the File menu:

Stata file menu

(I'll discuss using an external text editor in the next installment)

You'll see a blank file like this:

Blank do file

Next we'll write a few commands. Remember these are things you want Stata to do every time you open it. Unless you exclusively work with one dataset, I wouldn't suggest opening it through the do-file. This is more "background": how much memory do you want allocated, where do you want the working directory, things that won't change often.

Here's our simple do-file:

Simple do file text

It does three things:

  1. Sets the memory to 20m (the default is 1m). This can be done in the regular preferences pane also.
  2. Changes the working directory from "/Documents" to "/Documents/stata work/"
  3. Checks for updates to the executable and the .ado files.


Now, most importantly, you need to save the .do file in the right location. It needs to reside in the Libraries/Application Support/Stata directory:

Profile in directory

Re-start Stata and you should see something like this:

Picture 6.jpg

Success, the profile.do file is running as it should.

Next we'll deal with Step 3: Choosing an External Text Editor

No comments: