Speaking Stata: Loops, again and again
Nicholas Cox
Stata Journal, 2020, vol. 20, issue 4, 999-1015
Abstract:
Two commands in official Stata, foreach and forvalues, provide structures for looping through lists of values (variable names, numbers, arbitrary text) and repeating commands using members of those lists in turn. These com- mands may be used interactively, and none is restricted to use in Stata programs. They are explained and compared in some detail with a variety of examples. In addition, a self-contained exposition is given on local macros, understanding of which is needed for use of foreach and forvalues. This column is a revision of the column “How to face lists with fortitude”, which appeared in Stata Journal 2: 202–222 (2002). (The bizarre bibliographical details are too, too extraordinary not to be flagged but were pure happenstance.) The presentation here has been trimmed of now historic content and corrected, improved, and updated in several minor details.
Keywords: foreach; forvalues; lists; local macros; substitution first (search for similar items in EconPapers)
Date: 2020
Note: to access software from within Stata, net describe http://www.stata-journal.com/software/sj20-4/pr0074/
References: Add references at CitEc
Citations:
Downloads: (external link)
http://www.stata-journal.com/article.html?article=pr0074 link to article purchase
Related works:
This item may be available elsewhere in EconPapers: Search for items with the same title.
Export reference: BibTeX
RIS (EndNote, ProCite, RefMan)
HTML/Text
Persistent link: https://EconPapers.repec.org/RePEc:tsj:stataj:y:18:y:2018:i:4:p:999-1015
Ordering information: This journal article can be ordered from
http://www.stata-journal.com/subscription.html
DOI: 10.1177/1536867X20976340
Access Statistics for this article
Stata Journal is currently edited by Nicholas J. Cox and Stephen P. Jenkins
More articles in Stata Journal from StataCorp LLC
Bibliographic data for series maintained by Christopher F. Baum () and Lisa Gilmore ().