Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: how to write loop program for each value of a variable?
From
David Kantor <[email protected]>
To
[email protected]
Subject
Re: st: how to write loop program for each value of a variable?
Date
Thu, 03 May 2012 11:02:30 -0400
At 09:28 AM 5/3/2012, Qian wrote:
Hi, statalist
I want to write a loop program for each value of a variable, such as
a loop program about variable "v","q", "p" by the value of code(1,2,3),
the data is listed as following:
code v q p
1 4.65605 3.82133 .5891969
1 8.55465 3.273241 .1132121
1 .5072982 3.273241 .1132121
2 .0668553 3.781385 .112315
2 4.346485 3.999861 .1429252
2 .453282 3.389864 .27451
3 2.514498 2.554792 .432496
3 5.027869 3.869841 .1236284
. . .
. . . .
Then how to write such loop program?
[...]
You need to tell us more detail about what you want to do. As a
start, if you really want to write a loop,
you may want to use -levelsof- to gather the set of values of code;
then use -foreach- to loop over those
values.
But there is a good chance that you don't really need to write a
loop; your task may be solved by Stata's
implicit looping that occurs in most data-management commands. This
may also involve the use of the -by-
prefix.
HTH
--David
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/