Efficient directory switching with co-authors in Stata

If you've worked on Stata analyses with co-authors, or on different machines, you've probably seen stuff like this:

cd "Users/Paul/Dropbox/Research project" //Mac
*cd "C:/user/Paul/Dropbox/Research project" //Home PC
*cd "Users/John/Work/Dropbox/Research project" //John

You are working from a shared Dropbox folder, but the location of that folder is different on every computer you use, and also for each co-author. So everybody just adds their own directory location. I dislike this. It's messy, and it adds an extra action that you have to repeat for each dofile. And if your co-author makes some edits you have to comment theirs in and out again.

My preferred solution uses profile.do to define globals for each working directory. Profile.do is a small dofile that is run every time Stata starts. If you define a global (a persistent value) to the location of your dropbox folder, you just refer to that global when setting the working directory. What this looks like:

*profile.do: a dofile that is run everytime Stata starts

global DROPLOC "Users/Paul/Dropbox/"

And in your main dofile:

cd "$DROPLOC/Research Project"

When running that cd Stata will fill in what you earlier defined as DROPLOC, and fill in the location of your Dropbox folder. You need to set this up separately for each machine, but once you have you won't have to mess with it ever again.

This profile.do is just a normal dofile, but it needs to have a specific name (profile.do) and it has to be saved in a specific location. See here for more details. I like to save it in the folder Stata is installed in.


I've seen some people use a 'master' dofile that other dofiles are run from. This means you need to only make one change to the cd. That's less work, but still too much in my opinion.

I've also seen people do something like this:

capture cd "Users/Paul/Dropbox/Research project" //Mac
capture cd "C:/user/Paul/Dropbox/Research project" //Home PC
capture cd "Users/John/Work/Dropbox/Research project" //John

The capture command ensures that the dofile keeps running if the cd doesn't work. I dislike it because you still need to add your own directory location to it, potentially across many files. Plus, it just looks messy.

I've also seen people mention a user-written program called -project- which is available on SSC. It sounds like it could work, but it's more of a hassle as you need to install this program.

Other cool stuff

Profile.do is useful for other purposes as well. I also use it turn more off, but you could also use it to increase the memory can Stata use. And a little encouragement message! This is what my profile.do looks like on my Mac:

global DROPLOC "/Users/Paul/Dropbox"
global GITLOC "/Users/Paul/GitHub"

set more off, permanently

noisily: display "Paul is Cool"