Bookmark and Share

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]

st: Min value of a variable and an error in for loop


From   Mayank Mishra <[email protected]>
To   [email protected]
Subject   st: Min value of a variable and an error in for loop
Date   Sun, 26 Jun 2011 21:43:42 +0530

Hello all,

I need to find out the minimum value observation of a variable. I
tried the following loop to obtain it:

gen temp = val[1]                                // val is the
variable whose min value i intend to find
forvalues i=2/_N {
replace temp = val[`i'] if val[`i']<`temp[1]'
}
gen minval = `temp [1]'

the message i got was invalid syntax. Please tell me the problem with
this loop. I also tried

local temp

, instead of "gen temp" in first line, but got the same result.

Also, please tell me, if there is some other more efficient method to do this.

Thanks a lot.

OM

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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index