NetCourse 151: Introduction to Stata Programming

Course length:

6 weeks (4 lessons)

Price:

USD 150

Course leaders:

Kerry Kammire and Derek Wagner

Prerequisites:

Stata 15 installed and working.
Basic knowledge of using Stata interactively.
Internet web browser, installed and working.
(Course is platform independent)

Organization of analysis

  • Welcome
  • Entering and executing a program
  • The do-file
  • The interactive program command
  • program in a do-file
  • Combination do-files
  • Ado-files
  • Organizing do-files
  • An individual do-file
  • A do-file to perform verification
  • Infiling data
  • Reproducibility
  • Indexing
  • assert as an alternative to branching
  • Consuming calculated results

Macros, arguments, and looping

  • Macros
  • How macros might be used
  • Macro names
  • The related-persons example
  • Another example (plant data)
  • Potential problem—variable scope
  • More on arguments
  • Branching and looping
  • Physical program style
  • foreach
  • Looping across observations
  • if

Examples and applications

  • Data management example
  • Handling time and date variables
  • Checking assumptions
  • Returned values and storing results
    • What can be returned in r()?
    • Referring to returned results in other programs
    • Referring to returned results in the program that sets them
  • Bootstrapped standard errors
  • Aside: reading a trace
  • A warning on bootstrapping
  • Speeding up bootstrapping
  • Bootstrapping, how to
  • Monte Carlo simulations
  • postfile and post
  • Using quietly
  • Speeding up simulations

Ado-files

  • A first real ado-file
  • discard
  • More improvements to doanl
  • capture
  • The exit command
  • Making doanl a general tool
  • Writing a help file for doanl
  • Do-files, programs, and ado-files: When to use which
  • Temporary variables
  • Temporarily destroying data
  • Temporary files
  • An analysis-specific ado-file
  • General-purpose (GP) ado-files
  • A GP ado-file
  • Fine-tuning display output
  • Stata syntax
  • syntax
  • varlist macro
  • syntax’s other specifiers
  • Whether to use syntax
  • A note on quotes
  • Version control