UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Code Fragment: 
Using "for"

* lets start with a tiny file
clear
input id y80 y81
1  5  6
2 10 11
3 15 16
4  3  4
end

* you can use the "for" command to repeat a command over and over
for var y80 y81: summarize X
* The command above acts like you typed
summarize y80
summarize y81

* This is not useful for the summarize command, but it would
* be useful for a command that takes only one variable

* You can also combine this with global variables
global y "y80 y81"
for var $y: summarize X


How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California