NETCOURSE® 251: WRITING YOUR OWN STATA COMMANDS

CONTENT

Learn how to create and debug your own commands that are indistinguishable from the commands in Stata. You will be able to parse both standard and nonstandard Stata syntax using the intuitive syntax command, to manage and process saved results, to post your own saved results, to process by-groups, to create data management commands, to program your own maximum-likelihood estimator, and more. In short, learn to create commands that act just like the commands that ship with Stata.

 

PREREQUISITES

  • Stata 18 installed and working
  • Course content of NETCourse 151  or equivalent knowledge
  • Internet web browser, installed and working (course is platform independent)

PROGRAM

 

SESSION I: PARSING STATA SYNTAX/STATA PROGRAMMING BASICS

  1. Review of Stata’s programming features
  2. Parsing
  3. Parsing options
  4. Parsing complicated syntax
  5. Aside on subprograms

 

SESSION II: PARSING STATA SYNTAX, CONTINUED: QUOTES, RETURNED RESULTS, AND SUBSAMPLES

  1. Quotes
  2. Development continues
  3. Temporary variables
  4. Development continues
  5. An aside concerning r()
  6. Programming the formulas
  7. Putting it together

 

SESSION III: USING SCALARS AND MACROS AND INTRODUCTION TO LOW-LEVEL PARSING

  1. What you must learn
  2. Scalars
  3. Binary accuracy
  4. Accuracy of macros versus scalars
  5. Converting a program from macros to scalars
  6. Handling by() options
  7. Sorting
  8. Low-level parsing
  9. Programming immediate commands
  10. Rewriting mytt in terms of mytti
  11. Parsing new variables

 

 

 

 

 

 

 

 

 

 

© Copyright 1996–2024 StataCorp LLC

 

 

 

SESSION IV: RETURNING RESULTS AND WRITING ESTIMATION COMMANDS

  1. Where are we?
  2. Stored results
  3. What can be returned in r()?
  4. Referring to returned results in other programs
  5. Referring to returned results in the program that sets them
  6. Other types of returned values: s() and e()
  7. S-class returned values
  8. E-class returned results
  9. Writing postestimation commands
  10. Writing an estimation (e-class) command
  11. An alternative estimation command outline
  12. Writing estimation commands from first principles
  13. Writing estimation commands via maximum likelihood

 

SESSION V: LIST PROCESSING, CONTROLLING PROGRAM OUTPUT, AND NAMING CONVENTIONS

  1. Restricting commands to the relevant subsample
  2. Which is better: marksample or mark?
  3. Programming by varlist:
  4. Lists
  5. Creating lists
  6. Stepping through list elements one by one
  7. Deleting elements from lists
  8. Adding elements to lists
  9. Macro vectors
  10. Parsing revisited: gettoken
  11. quietly blocks
  12. The relation between capture and quietly
  13. capture blocks
  14. Naming conventions
  15. Program-naming convention
  16. Calling convention
  17. Version control

 

 

Note: There is a one-week break between the posting of Sessions 3 and 4; however, course leaders are available for discussion.