help lookfor_val

Title

lookfor_val -- Search for value patterns in current data set

Syntax

lookfor_val [varlist] [,options]

pattern(pattern) specify value pattern to be searched for

values display and save values that match pattern; default is to
display and save variable names

numeric only search in numeric variables

string only search in string variables

insensitive perform case-insensitive search

missing treat missing values as valid

describe describe variables if variables match the specified
pattern

tabulate tabulate variables if variables match the specified
pattern

list list variables if variables match the specified
pattern

noprint do not display list(s)

separate(sep) use sep as separator in returned list(S)

Description

lookfor_val searches the current data set for values that match a specified
pattern. Variable names are displayed and stored in r(varlist) if any value of a
variable matches the pattern specified. Numeric and string variables are searched. If
varlist is not specified it defaults to _all.

Caution: the program loops over every single level of every variable specified. This
process may take a long time if your data set is large.

Options

Options

pattern(pattern) specifies the value pattern to be searched for. Wildcards like
"*" and "?" may be used, where the former means zero or more characters and the
latter means exactly one character. If not specified, pattern defaults to *,
meaning that all variables specified in varlist will be listet. If values is
specified all non-missing values of every variable in varlist will be listet.

values displays the values of every variable in varlist that match the specified
pattern. The values are returned in r(values_varname). If specified
lookfor_val does neither display nor save a list of variable names.

numeric specifies that only numeric variables will be searched. If pattern()
is not specified, only numeric variables will be listet.

string specifies that only string variables will be searched. If pattern()
is not specified, only string variables will be listet.

insensitive performs case-insensitve search. This option will only affect the search
performed in string variables of course.

missing treats missing values as valid. Specifiy missing if you wish to search
for missing values (i.e. ., .a, .b, ..., .z or "") in variables.
If missing is specified without the pattern() option, pattern will be set
to "" (or . if numeric is also specified).

describe describe variables if variables match the specified pattern. This
option may not be used with values.

tabulate tabulates variables if variables match the specified pattern. This
option implies the values option and values will be returned in
r(values_varname) but will not be displayed.

list lists variables if variables match the specified pattern. This option
implies the values option and values will be returned in
r(values_varname) but will not be displayed.

noprint does not display the list(s) returned in r().

separate(sep) uses sep as separator between elements in the returned list(s).
The default is " ". If inlist is to be used with the lists, specify
separate(,).

Example

. sysuse auto ,clear
(1978 Automobile Data)

. lookfor_val ,pattern(*v*)
make

. lookfor_val make ,pattern(*v*) values insensitive tabulate

-> tabulation of make if make has value pattern *v*

Make and Model | Freq. Percent Cum.
-------------------+-----------------------------------
Buick Riviera | 1 5.56 5.56
Cad. Deville | 1 5.56 11.11
Cad. Seville | 1 5.56 16.67
Chev. Chevette | 1 5.56 22.22
Chev. Impala | 1 5.56 27.78
Chev. Malibu | 1 5.56 33.33
Chev. Monte Carlo | 1 5.56 38.89
Chev. Monza | 1 5.56 44.44
Chev. Nova | 1 5.56 50.00
Honda Civic | 1 5.56 55.56
Linc. Mark V | 1 5.56 61.11
Linc. Versailles | 1 5.56 66.67
Plym. Volare | 1 5.56 72.22
VW Dasher | 1 5.56 77.78
VW Diesel | 1 5.56 83.33
VW Rabbit | 1 5.56 88.89
VW Scirocco | 1 5.56 94.44
Volvo 260 | 1 5.56 100.00
-------------------+-----------------------------------
Total | 18 100.00

Please note that the values option may be omitted, since
it is implied by tabulate.

. lookfor_val ,pattern(199*) values noprint

. return list

macros:
r(values_length) : "199"
r(values_weight) : "1990"

Saved results

lookfor_val saves one of the following in r():

r(varlist) list of variables with specified value pattern

r(values_varname) values in varname that match pattern
(option values)

Author

Daniel Klein, University of Bamberg, daniel1.klein@gmx.de

Also see

Online: ds, lookfor

if installed: lookfor_all