Find a specific value ---------------------
^findval^ value [varlist] [^if^ exp] [^in^ range], [^sub^str ^gen^erate^(^newvarname^)^]
Description -----------
^findval^ finds, lists and stores in ^r(vars)^ the variables that take the specified value in the given range or condition. If no varlist specified, all variables are included into search. ^findval^ can also deal with string values -- take care, as you might forget the value as the first argument, and ^findval^ would then search for the string coinciding with the first variable in your list...
Options -------
^substr^ specifies that value be considered as a substring rather than the exact match; only applicable to string values.
^generate^ creates a 0/1 variable set to one if the match is found in the observation, and missing if the ^if^ or ^in^ conditions are not satisfied.
Examples --------
. ^use auto^ (1978 Automobile Data)
. ^findval 100^ The value of ^100^ is never found.
. ^findval 5^ The value of ^5^ is found in variables: ^rep78 hdroom trunk^
. ^findval 5, gen(match5)^ The value of ^5^ is found in variables: ^rep78 hdroom trunk^
. ^findval 5, gen(match5f), if foreign^ The value of ^5^ is found in variables: ^rep78 trunk^
. ^li make `r(vars)' if match5f & match5f<.^
make rep78 trunk 53. Audi 5000 5 15 57. Datsun 210 5 8 61. Honda Accord 5 10 62. Honda Civic 4 5 66. Subaru 5 11 67. Toyota Celica 5 14 68. Toyota Corolla 5 9 69. Toyota Corona 5 11 71. VW Diesel 5 15 74. Volvo 260 5 14
Mind the use of quotes for ^r(vars)^ here! The returned value is a local macro, so you should put it in quotes to get anything from it.
. ^sum match*^
Variable | Obs Mean Std. Dev. Min Max ---------+----------------------------------------------------- match5 | 74 .1756757 .3831416 0 1 match5f | 22 .4545455 .5096472 0 1
. ^findval Ford^ The value of ^Ford^ is never found.
. ^findval Ford, sub^ The value of ^Ford^ is found in variables: ^make^
Returned values ---------------
^r(vars)^ the list of the variables containing the specified value; not defined if none found. ^r(value)^ the number or the string searched for.
See also --------
Online: @lookfor@
Author ------
Stas Kolenikov, skolenik@@recep.glasnet.ru