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

st: Re: using the max command (function)


From   Christopher F Baum <[email protected]>
To   [email protected]
Subject   st: Re: using the max command (function)
Date   Sat, 7 Feb 2004 08:20:47 -0500

On Feb 7, 2004, at 2:33 AM, Amit wrote:

I have a variable for which I need the maximum element. So, I typed:

egen element=max(var5)

Now, I need to use this value in a for-loop

foreach i=1(1)element {
...
}


Presuming that the variable contains integers:

quietly summ var5
local hi5 = r(max)
forvalues i=1/`hi5' {
...
}

Note that if you want to count, you should use forvalues, not foreach.

Kit

*
*   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