Linda Wang
April 2023
These slides are based on the Stata-related procedures section of the training manual.
include config.do
at the beginning and log close _all
at the end of the .do file(s) you will run.If the authors do not provide a master .do, but the order in which each program is run is clear (either from file names or from the README), then create a master.do as follows:
include config.do
for the first line and log close _all
for the last line.do
and the path. Make sure these lines are in the right sequence.include "config.do"
* Assuming scenario "A"
do "${rootdir}/code/0_first_program.do"
do "${rootdir}/code/1_second_program.do"
do "${rootdir}/code/2_third_program.do"
do "${rootdir}/code/appendix_code/appendix.do"
log close _all
Before:
*/ This is Master do file /*
global maindir "C:\Users\Author\Dropbox\Project1" // this is the path to the repository
global data "$maindir/data" // path to data folder
global figures "$maindir/figures" // path to figures folder
After:
include "config.do"
*/ This is Master do file /*
global maindir "$rootdir" // this is the path to the repository
global data "$maindir/data" // path to data folder
global figures "$maindir/figures" // path to figures folder
E.g.
log using "${path}\Output\maindata.log", replace
(file U:\AEAworkspace\aearep-3835\182763\Output\maindata.log not found)
file U:\AEAworkspace\aearep-3835\182763\Output\maindata.log could not be opened
r(603)
scenario
that is set to A
by default.
A
indicates the case where the master .do file is in a subfolder of the root directory.B
indicates the case where the master .do file is in the root directory. Change the default if needed.Scenario A
directory/
code/
main.do
01_dosomething.do
data/
data.dta
otherdata.dta
Scenario B
directory/
main.do
scripts/
01_dosomething.do
data/
data.dta
otherdata.dta
Execute (do)
. This will set the working directory location to the location where the master .do file is, automatically."C:/Program Files/Stata17/StataMP-64.exe" -b do "U:/test/master.do"
'C:\Program Files\Stata16\StataMP-64.exe' /b do .\master.do
stata-mp -b do master.do
command not found
or type ssc install
, and can be resolved through modifications to config.do.scan_packages.do
may be generating some of these errors.
config.do
before running code for the first time. (An exception would be if the README indicates long runtimes.)