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

Re: st: Programming question


From   David Kantor <[email protected]>
To   [email protected]
Subject   Re: st: Programming question
Date   Fri, 04 Mar 2005 12:58:08 -0500

At 12:00 PM 3/4/2005 -0500, Cameron Hooper wrote:
A novice programming question. Say I have the following data

id x
1 1
1 2
1 4
2 2
2 8
2 6
2 2

I want to write a program to loop through each company (represented by id) and then within each company loop through each observation. Something like:

forvalues i = 1(1)<number of companies> {
for values j = 1(1)<number of observations for company `i'> {
<do stuff>
}
}

[...]
I might add to my previous message: one way to do the outer loop might be (untested, and I have no experience yet with -levels-)...

levels id, local(idlist)
foreach i of local idlist {
<do stuff>
}

But, again, I guess that looping may be unnecessary.

-- David

David Kantor
Institute for Policy Studies
Johns Hopkins University
[email protected]
410-516-5404
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




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