Every time you start a new Stata session make it a habit to:
- Change the working directory, and
- Create a log file.
The first step allows you to link the Stata session to a folder on your computer’s hard drive and the second step creates a permanent record of your results.
For example, let’s assume you have a folder labeled data on your C:\ drive where you keep all the project files. It doesn’t have to be a C:\ drive it could be a folder on your USB drive or Dropbox. Go ahead and create the data folder. Next, from the menu bar select File > Change working directory on the main menu bar. From the pop-up window browse to the data folder and click OK. The Stata session is now linked to the data folder.
When you create a log file using a Stata command in the next step you don’t have to specify the complete path. It saves time. You will notice that the folder path in the lower left window has changed in my case to D:\data. When you use point-and-click menu, Stata automatically generates a command in the Results window: cd “D:\data”
Now, let’s create a log file. Stata allows you to create a log file with .log (a text file) or .smcl (Stata Markup and Control Language) extension. I recommend creating the log files with .log extension, which can be opened using a notepad. SMCL log files can only be opened from within Stata.
You can create a log file using the menu bar File > Log > Begin. From the pop-up window browse for the data folder, name the log file, make sure to save it as .log (the default is smcl) and click OK.
The Results window will show 1) the command (syntax) Stata used to create the log file, 2) time stamp, and 3) will indicate if the log is currently on. You can temporarily turn off the log by typing
in the command window. To exit the log just type
Log files are saved automatically. All Stata commands are lowercase.
Let’s say you want to use an existing log file that you created in an earlier Stata session. Once you start a new Stata session and change the working directory to link the Stata session to the folder go through the same step as before File > Log > Begin. From the pop-up window browse for the data folder, select the existing log file, make sure to select .log (the default is smcl) extension from the drop-down menu and click Save. A small window will appear. Select Append to existing file and click OK
Alternately, you can simply type
log using project.log, append
You don’t to type the complete path (i.e., D:\data\…) as long as you have linked the Stata session to the folder where the project.log file resides. Read the blog post on Creating a Log File to learn how to change the working directory.
You are now ready to open and analyze a Stata dataset.