This section is a gentle introduction to programming Stata. I discuss macros and loops, and show how to write your own (simple) programs. This is a large subject and all I can hope to do here is provide a few tips that hopefully will spark your interest in further study. However, the material covered will help you use Stata more effectively.
Stata 9 introduced a new and extremely powerful matrix programming language called Mata, and Stata 16 expanded the choice of languages by integrating Python. In addition, it is possible to write Stata plugins in C or Java. All of these languages are beyond the scope of this introductory tutorial. Your efforts here will not be wasted, however, because the options are complementary to, not a complete substitute for, classic Stata programming.
To learn more about programming Stata I recommend Kit Baum’s An Introduction to Stata Programming,