Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: for commands

From   "Dimitriy V. Masterov" <>
Subject   Re: st: for commands
Date   Tue, 4 Nov 2003 15:39:17 -0600 (CST)

Mr. Eggers,

I am not sure what operation you're trying to do, but you can try
something like this:

foreach elem in a b c {
	forvalues n=1/5 {
		foreach var of varlist x1-x5 {

			di " elem is `elem', n is `n', and var is `var' "

All this does is display some text based on the three loops that I have
defined. Variables x1-x5 need be defined for the innermost loop to work.
You can define them in the following way, which is also an example of a
simple loop:

forvalues i=1/5 {
	gen x`i'=`i'

This will create x1-x5 where x1=1 for all observations, x2=2 and so on.

There is a great pdf by N. Cox about lists that I've found very helpful
in the past. It can be found at

I hope this helps.


Dimitriy V. Masterov

Center for Social Program Evaluation
1155 East 60th St. Room 038
Chicago, IL 60637
Work: (773)256-6005
Fax: (773)256-6313

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index