help findname                                                (SJ12-1: dm0048_2)
-------------------------------------------------------------------------------

Title

findname -- List variables matching name patterns or other properties

Syntax

findname [varlist] [if] [in] [, options]

options Description ------------------------------------------------------------------------- Control insensitive perform case-insensitive pattern matching local(macname) put list of variable names in local macro macname not list variable names not in varlist placeholder(symbol) specify alternative to @

Display alpha list variable names in alphabetical order detail display additional details indent(#) indent output skip(#) gap between variables; default is skip(2) varwidth(#) display width for variable names; default is varwidth(12)

Selection by data types, values, and formats type(typelist) has specified type all(condition) has all values satisfying condition any(condition) has any values satisfying condition format(patternlist) has display format matching patternlist

Selection by variable and value labels varlabel has variable label varlabeltext(patternlist) has variable label with text matching patternlist vallabel has value label vallabelname(patternlist) has value label with name matching patternlist vallabeltext(patternlist) has value label with text matching patternlist

Selection by characteristics char has characteristic(s) charname(patternlist) has characteristic(s) with name matching patternlist chartext(patternlist) has characteristic(s) with text matching patternlist

-------------------------------------------------------------------------

typelist used in type(typelist) is a list of one or more types, each of which may be numeric, string, byte, int, long, float, or double, or may be a numlist such as 1/8 to mean str1 str2 ... str8. Examples include

type(int) is of type int type(byte int long) is of integer type type(numeric) is a numeric variable type(1/40) is str1, str2, ..., str40 type(numeric 1/2) is numeric or str1 or str2

patternlist used in, for example, format(patternlist), is a list of one or more patterns. A pattern is the expected name or text with the likely addition of the characters * and ?. * indicates 0 or more characters go here and ? indicates exactly 1 character goes here. Examples include

format(*f) format is %#.#f format(%t*) has time or date format format(%-*s) is a left-justified string varl(*weight*) variable label includes word weight varl(*weight* *Weight*) variable label includes word weight or Weight

To match a phrase, it is important to enclose the entire phrase in quotes.

varl("*some phrase*") variable label has some phrase

If instead you used varl(*some phrase*), then only variables having labels ending in some or starting with phrase would be listed.

condition used in all() or any() is a true-or-false condition defined by an expression in which variable names are represented by @. For example, any(@ < 0) selects numeric variables in which any values are negative.

Description

findname lists variable names of the dataset currently in memory in a compact or detailed format, and lets you specify subsets of variables to be listed, either by name or by properties (e.g., the variables are numeric). In addition, findname leaves behind in r(varlist) the names of variables selected so that you can use them in a subsequent command.

findname, typed without arguments, lists all variable names of the dataset currently in memory in a compact form.

If two or more options specifying properties of variables are specified, findname identifies only those variables that satisfy all of the option specifications, i.e. the intersection of all the subsets identified. The not option provides a direct way to identify the complementary set. Two or more calls to findname with results saved in local macros using the local() option may be used together with macro operations to produce the union, set difference, etc. of different subsets.

if and in when specified only affect the operation of any(), all() or vallabeltext().

Options

+---------+ ----+ Control +----------------------------------------------------------

insensitive specifies that the matching of any pattern in patternlist be case-insensitive. For example, varl(*weight*) inse is an alternative to, and more inclusive than, varl(*weight* *Weight*).

local(macname) puts the resulting list of variable names into local macro macname.

not specifies that varlist and/or the specifications given define the set of variables not to be listed. For instance, findname pop*, not specifies that all variables not starting with the letters pop be listed. The default is to list all the variables in the dataset or, if varlist and/or particular properties are specified, the variable names so defined.

placeholder(symbol) specifies an alternative to @ to use in any() or all() options. This should only be necessary for making string comparisons involving @ as a literal character, or if bizarrely your @ key is damaged or otherwise unavailable.

+---------+ ----+ Display +----------------------------------------------------------

alpha specifies that the variable names be listed in alphabetical order.

detail specifies that detailed output identical to that of describe be produced. If detail is specified, indent(), skip() and varwidth() are ignored.

indent(#) specifies the amount the lines are indented.

skip(#) specifies the number of spaces between variable names; the default is skip(2).

varwidth(#) specifies the display width of the variable names; the default is varwidth(12).

+----------------------------------------------+ ----+ Selection by data types, values, and formats +---------------------

type(typelist) selects variables of the specified typelist. Typing findname, type(string) would list all names of string variables in the dataset, and typing findname pop*, type(string) would list all names of string variables beginning with the letters pop.

all(condition) selects variables which have all values satisfying condition. If either if or in is specified, attention is restricted to the observations specified.

any(condition) selects variables which have any values satisfying condition. If either if or in is specified, attention is restricted to the observations specified.

With either all() or any() conditions that mismatch type are ignored.

format(patternlist) selects variables whose format matches any of the patterns in patternlist. format(*f) would select all variables with formats ending in f, which presumably would be all %#.#f, %0#.#f, and %-#.#f formats. format(*f *fc) would select all ending in f or fc.

+----------------------------------------+ ----+ Selection by variable and value labels +---------------------------

varlabel selects variables with defined variable labels.

varlabeltext(patternlist) selects variables with variable label text matching any of the words or phrases in patternlist.

vallabel selects variables with defined value labels.

vallabelname(patternlist) selects variables with value label names matching any of the words in patternlist.

vallabeltext(patternlist) selects variables with value label text matching any of the words or phrases in patternlist. If either if or in is specified, attention is restricted to the observations specified. Either way, no attention is paid to value labels that do not correspond to values present in the data.

+------------------------------+ ----+ Selection by characteristics +-------------------------------------

char selects variables with defined characteristics. Note that notes are characteristics.

charname(patternlist) selects variables with characteristic names matching any of the words in patternlist.

chartext(patternlist) selects variables with characteristic text matching any of the words or phrases in patternlist.

Examples

All variables

. findname

All string variables

. findname, type(string) . edit `r(varlist)'

All str1, str2, str3, str4 variables

. findname, type(1/4)

All numeric variables

. findname, type(numeric) . order `r(varlist)'

. findname, type(numeric) . summarize `r(varlist)'

All byte or int variables

. findname, type(byte int)

All float variables

. findname, type(float)

All variables that are not float

. findname, type(float) not

All date variables, i.e., those with formats %t* or %-t*

. findname, format(%t* %-t*)

All variables with only integer values

. findname, all(@ == int(@))

All variables with any negative values

. findname, any(@ < 0)

Variables with left-justified string formats

. findname, format(%-*s)

Variables with comma formats

. findname, format(*c)

All variables with value labels attached

. findname, vall

All variables with the value label origin attached

. findname, vall(origin)

Variables with characteristics defined

. findname, char

Variables with notes

. findname, charname(note*)

Find text in characteristics

. notes mpg : hidden treasure . findname, chartext(*treasure*)

Author

Nicholas J. Cox, Durham University, U.K. n.j.cox@durham.ac.uk

Acknowledgments

findname owes a major debt to ds. ds and its relatives under differing names have had a complicated history in various official and user-written versions (e.g. Anonymous 1992; Cox 2000, 2001; Weiss 2008; and ds2, ds3, ds5 on SSC). The author's earlier work was aided by suggestions from Richard Goldstein, William Gould, Jay Kaufman, and Fred Wolfe. More recently Maarten Buis, Martin Weiss, Vince Wiggins and several members of Statalist provided helpful comments both directly and indirectly. Jeremy Reynolds found a bug in the version originally published in Stata Journal 10(2). Marc Kaulisch pointed out a problem with handling of double quote characters embedded within text (e.g. within variable labels).

References

Anonymous. 1992. Short describes, finding variables, and codebooks. Stata Technical Bulletin 8: 3-5. (STB Reprints 2: 11-14.)

Cox, N.J. 2000. Describing variables in memory. Stata Technical Bulletin 56: 2-4. (STB Reprints 10: 15-17.)

Cox, N.J. 2001. Describing variables in memory: update to Stata 7. Stata Technical Bulletin 60: 3. (STB Reprints 10: 17.)

Cox, N.J. 2010. Speaking Stata: Finding variables. Stata Journal 10: 281-296.

Weiss, M. 2008. Stata tip 66: ds-A hidden gem. Stata Journal 8: 448-449.

Also see

Manual: [D] ds

Help: [D] compress, [D] codebook, [D] describe, [D] ds, [D] format, [D] label, [D] lookfor, [D] notes, [D] order, [D] rename