How to Permanently Change the Working Directory in Stata for Linux

We can easily change the default working directory in Stata for Linux/Unix by adding three lines of code to the file.

Changing the default working directory in Stata for Linux/Unix is only a matter of entering three lines of code in one file. To my surprise, this information was hard to find. So I thought I’d document the steps I took to change my default working directory/folder on CrunchBang Linux.

Before the change, the default working directory in my Linux box was ~/stata10.

I wanted my new default directory to be called malariatrial and its path to be ~/stata10/malariatrial.

Step 1: Create a new directory

I created a new directory in the directory ~/stata10 and named it malariatrial. You can call your new directory anything you want but be sure to substitute malariatrial in the steps below with your chosen directory name.

Step 2: Add a program to the file

Look for the file, which is a do-file that Stata executes every time we launch it. In my system, I found the file as a hidden file in the home directory.

Open the file with a text editor, and at the bottom of the file, add the following three lines of code:

program defaultdir 
cd ~/stata10/malariatrial 

Close the file and reboot.

You should now enter the new directory (~/stata10/malariatrial, in my case) whenever you open Stata.

That’s it, and there is no step 3. 🙂

1 comment add your comment

  1. Thanks for providing this very useful information. I’m a bit surprised that STATA does not include an option to make a particular directory the default working directory.

Leave a Comment