Stata Training

Linda Wang

April 2023

How to Run Stata Code

These slides are based on the Stata-related procedures section of the training manual.

config.do

Purpose

Set up

Walkthrough

Package Installation

Present/Working Directory Set Up

Diagnostics

Other

master.do

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"
 
* 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

General Stata Tips

Modifying File Paths

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 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

Running the Code

"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

Missing Package(s)