Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[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 <mayankm16@gmail.com>
To   statalist@hsphsun2.harvard.edu
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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index