| name | main-dofile |
| description | Create or update a main Stata do-file (main.do) running all other scripts. Use for: setting up main.do; or updating main.do when a new do-file is created or renamed. |
STEPS:
- Identify if a main dofile already exists. It may be called
main.do, master.do, or run.do. If does not exists, continue with the steps in the "Create Main Do-File" section. If it does exist, continue with the steps in the "Update Main Do-File" section.
Do not try to run the main.do file as a way of verifying that it is correct. Most intended users of this skill will not have a setup where Stata can be executed through the command line. Instead, verify that the main.do file is correct by checking that it contains all of the other do-files in the project in the correct order.
Create Main Do-File
- Copy the template from
./templates/main.do to an appropriate location. This should be the root of where other code files are located. If you do not identify an obvious location, suggest locations to the user and ask them to choose one.
- Populate the main do-file with the list of all other scripts in the project. Search documentation for the order the scripts should be run. If no order is specified, see if the naming of the scripts can be used to determine the order. If no order can be determined, ask the user to specify the order.
Update Main Do-File
- Each time a do-file is added, deleted or renamed, the main do-file should be updated to reflect the change. If a new do-file is added, it should be added to the main do-file in the appropriate order. If a do-file is deleted, it should be removed from the main do-file. If a do-file is renamed, the old name should be removed and the new name should be added in the appropriate order.
Checks after main.do is created or updated
- Make sure the root globals are set correctly in the main do-file. Do not use a root path that depends on the working directory. Instead, use the user's computer root to define the project root.
- Make sure that the root global is not re-set in any of the other do-files. The root global should only be set in the main do-file.
- This includes using
cd to change the working directory or setting a global to the users computer root in any of the other do-files.
- If you are removing any root globals from other do-files, make sure to replace those globals with the global that is set in the main do-file such that all do-files are using the same root global.
- Use
do not run — do echoes commands to the log; run silences them. Prefer do for reproducibility.
- Clear state — begin with
clear all and set more off to avoid carry-over state.
- Version pin — use
version to pin Stata version for forward compatibility.