How to Convert String Variables With Non-Numeric Values to Numeric Variables in Stata
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 profile.do 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 program.do file
Look for the program.do file, which is a do-file that Stata executes every time we launch it. In my system, I found the program.do file as a hidden file in the home directory.
Open the program.do file with a text editor, and at the bottom of the file, add the following three lines of code:
program defaultdir
cd ~/stata10/malariatrial
end
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. 🙂
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.