Writing User-Written Stata Commands
Rosemarie Sandino
Technical Products Coordinator
RST, November 2021
Objectives
Coding Best Practices
Coding vs. Programming
Coding vs. Programming
When to Write a User-Written Command
Designing a User-Written Command
Pseudocode
// receive 2 variables from user
// confirm that variables 1 & 2 are numeric
// t-test variables
// display the p-value
Writing a User-Written Command
Program
Structure of A Command
Syntax
Syntax: Command
Pop Quiz!
Syntax: Options
Syntax: Defaults and Constraints
Syntax: Other Considerations
Syntax Practice
Syntax Practice
Creating Your Own Errors & Checks
exit [errorcode]
Try for yourself!
General Programming Best Practices
Best Practices
Best Practices
Best Practices
References