Gabi over at The Stata Things posts a neat Stata trick using a profile.do file, which is a file with commands that are run each time you start Stata. You place some commands into a file, name it profile.do and then make sure that it’s in a location on your computer that Stata knows where to look for it. When Stata starts, it scans the following locations in order:
- Directory where Stata was installed;
- Current directory;
- along your Unix (or Mac) PATH or in your HOME directory on Windows;
- along the adopath.
I have my profile.do saved in ~/ado/personal/, which is as good a place as any. In my profile.do file, the only task I keep is to set boost the memory up to a few gigs since I have plenty of memory on my computer and I don’t like dealing with lack of memory errors. This is simply:
set mem 2048m
Gabi uses his profile.do file to log all commands to a file with the current date as a name so that he can review his interactive commands and copy-paste them into a do-file or ado program later – a good plan. I used to log all commands and output to a file using profile.do using this code:
*Start logging
local d = "$S_DATE"
cap log close
cap log off
cap log using "${LOG}$S_DATE.smcl"
Ultimately, I decided to drop this from my profile.do file because the log files were getting huge and I had to keep going in to clean things up. I also never found myself using the logs.
Another trick that I used for a time was to set a bunch of global variables every time that Stata starts and use that for setting directory locations that I’d commonly use. For a while I was putting all my Stata work into one directory which was further broken down into sub-folders for raw data, logs, do-files, output, graphs, etc. This is what that code looked like:
* set global folder locations
global SOURCE "/home/andrew/Dropbox/Stata/"
global RAW "${SOURCE}raw/"
global LOG "${SOURCE}log/"
global DO "${SOURCE}do/"
global GRAPH "${SOURCE}graph/"
global OUTDATA "${SOURCE}outdata/"
global OUTPUT "${SOURCE}output/"
global WD "${SOURCE}wd/"
Then anytime I wanted to load a raw data file called data.dta I’d type in:
use "${RAW}data.dta", clear
I ended up dropping this bit from my profile.do file as well as the number of projects I worked on exploded and the files in each of these folders got crazy. Now I have a projects folder with subdirectories by project.
I’m sure there are all kinds of other profile.do hacks out there, so if you have one, please share in the comments or by e-mail.
Some additional posts on profile.do use are at the links below. Check them out!
- Stata.com Help: profile
- Stata.com FAQ: profile.do
- Stata on a Mac: Setting up profile.do
- Datamonkey: profile.do
Good luck!

