Affiliation:
1. Department of Geography, Durham University Durham, UK,
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 commands 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.
Subject
Mathematics (miscellaneous)
Cited by
8 articles.
订阅此论文施引文献
订阅此论文施引文献,注册后可以免费订阅5篇论文的施引文献,订阅后可以查看论文全部施引文献
1. Programming Style: Suggested Guidelines for Writing Code;Australian Economic Review;2024-06-05
2. Speaking Stata: Automating axis labels: Nice numbers and transformed scales;The Stata Journal: Promoting communications on statistics and Stata;2022-12
3. Coding Style and Practice: Are All Programs Equal?;SSRN Electronic Journal;2022
4. Stata tip 144: Adding variable text to graphs that use a by() option;The Stata Journal: Promoting communications on statistics and Stata;2021-12
5. Speaking Stata: Loops in parallel;The Stata Journal: Promoting communications on statistics and Stata;2021-12