Reputation: 2529
I want to find the observation numbers that correspond to the observations that have a particular value, say 29
. I would then like to save these observation numbers in a macro.
Is there a better way to do so than the following clunky and inefficient forvalues
loop?
sysuse auto, clear
local n
forvalues i=1/`=_N' {
if mpg[`i']==29 local n `n' `i'
}
display "`n'"
Upvotes: 0
Views: 1097
Reputation: 37208
gen long obsno = _n
levelsof obsno if mpg == 29
is less typing for you. Why do you want this?
Upvotes: 2