Stata Tip 85: Looping over Nonintegers

A loop over integers is the most common kind of loop over numbers in Stata programming, as indeed in programming generally. forvalues, foreach, and while may be used for such loops. See their manual entries in the Programming Reference Manual for more details if desired. Cox (2002) gives a basic tutorial on forvalues and foreach. In this tip, I will focus on forvalues, but the main message here applies also to the other constructs. Sometimes users want to loop over nonintegers. The help for forvalues contains an example: