command | [action] |
---|---|
3.1. do filename | [ runs commands in file.do ] |
3.2. log using filename, replace | [ makes a full record of your Stata session ] |
3.3. doedit | [ opens do-file editor ] |
Do-files are are text files that contain commands that can be executed by Stata (they end with .do). There are 3 ways you can use Stata. First, you can use the drop down menus. This may seem easier when you are beginning but there are a lot of limitations to this method. Second, you can enter commands directly into the command prompt has we have been doing in class. The third and prefered way, however, is to use a do-file. A do-file allows you to reproduce your work in the future. It also means you don't have to start from scratch each time you open Stata. You can save your do-file close Stata and go home without worrying about losing your progress.
You can create a do-file using any text editor on your computer or you can use the built-in do-file editor in Stata (ctrl+9 or command doedit
)
When you use a do-file it is important that you provide clear infomration about the do-file's purpose. It is also important that you use relative file paths. If you use absolute file paths your do-file will not run on a diffrent computer. Finally, make sure you include comments so you can remember why you included specific commands and so that others can follow what you are doing.
There are 4 ways you can add comments in your do-file. This means that Stata will ignore them when running the commands.
• Begin line with * and Stata will ignore the line
• Place the comment inside /* */
• Place the comment after //
• Place the comment after /// to join the next line with the current one
Stata also allows you to keep a log of your session. It is good practice to start each do-file by opening a log.
Here is an example of a basic do-file. After looking at this example, make your own do-file. Make sure you include a log-file, comments, and some commands. Also, remember to close your log file after you're finished. After you run your do-file, make sure you can find the log-file Stata produced. It will be in your working directory.