-------------------------------------------------------------------------------
help for ds3
-------------------------------------------------------------------------------

Describe variables in memory

ds3 [varlist] [if exp] [in range] [, string[(numlist)] numeric byte int long float double complement { has(specification) | not(specification) | all(condition) | any(condition) | none(condition) } case placeholder(symbol) detail cols(#) ]

where specification is one of

varlabel [patternlist]

vallabel [patternlist]

format patternlist

char [patternlist]

(for more details, see under Rule 4 below);

and where condition is any true or false condition in which a single variable name may be substituted for the placeholder, by default X, which must appear at least once

(for more details, see under Rule 5 below).

Description

ds3 lists variable names in a compact format (or optionally, in the same format as describe). It is a variant on ds.

Options

ds3 may be considered as applying seven rules in succession.

Rule 1

ds3 starts with a varlist. If not supplied, varlist is a list of all variables in memory.

If there are no options, ds3 stops here and prints out varlist. This alone can be very useful. In this form, it is exactly equivalent to ds.

Rule 2

If any of the options string, numeric, byte, int, long, float or double are specified, then ds3 selects from the varlist those variables that are of the types specified.

string may take a numlist of any integers between 1 and 80, or between 1 and 244 under Stata/SE. For example, str(1/10) specifies variables of types str1, str2, ..., str9, str10 and str(42) specifies variables of type str42. str(1/80), or str(1/244) under Stata/SE, is thus a synonym for string, although string is recommended.

Rule 3

If the complement option is specified, then the varlist is replaced by its complement, i.e. all those variables not in varlist. Thus ds3, float complement produces a list of those variables that are not of type float.

Rule 4

Either the has() or the not() option may be specified (but not both, and not in conjunction with any of the all(), any() or none() options described under Rule 5).

The has() option specifies further features: those variables will be listed from the varlist that have those features.

The not() option also specifies further features: those variables will be listed from the varlist that do not have those features.

The specification may refer to one of the following: variable labels, value labels, formats or characteristics. The specification must start with one of the keywords varlabel, vallabel, format or char, which may be abbreviated varl, vall, f and c.

has(varl) specifies variables with defined variable labels and not(varl) specifies variables without such labels.

has(varl patternlist) and not(varl patternlist) refer to variable labels that satisfy one or more of the specified patterns.

has(vall) specifies variables with defined value labels and not(vall) specifies variables without such labels.

has(vall patternlist) and not(vall patternlist) refer to value labels whose names satisfy one or more of the specified patterns.

has(f patternlist) and not(f patternlist) refer to display formats satisfying specified patterns. In specifying a format the leading character % may be omitted.

Note that has(f) and not(f) are considered to be errors: because all variables have some display format, the answer to each would be totally predictable.

has(c) specifies variables with defined characteristics and not(c) specifies variables without such characteristics.

has(c patternlist) and not(c patternlist) refer to characteristics whose names satisfy one or more of the specified patterns.

The keywords or their abbreviations varl, vall, f and c and any patterns specified must be separated by spaces.

In specifying patterns, use the syntax used in the match(,) function. That is, * means "0 or more characters go here", ? means "1 character goes here" and any other character stands for itself. Comparison is case-sensitive unless the option case is specified. Thus has(vall origin) would not catch any variables with the value label Origin, but has(vall origin) case would do so.

Rule 5

One of the all(), any() and none() options may be specified (but not in conjunction with either of the has() and not() options described under Rule 4).

The all() option specifies a condition: those variables will be listed from the varlist for which all values satisfy that condition.

The any() option specifies a condition: those variables will be listed from the varlist for which any values (one or more) satisfy that condition.

The none() option specifies a condition: those variables will be listed from the varlist for which no values satisfy that condition.

The condition should be a true or false condition in which a placeholder, by default X, appears at least once. This placeholder will be substituted by each varname in the varlist. Thus any(X < 0) would be used to test whether each variable in the varlist contains negative values.

Any condition which makes no sense for numeric variables, such as X == "", will be ignored for those variables, and any condition which makes no sense for string variables, such as X < 0, will be ignored for those variables, irrespective of which variables appear in the varlist.

Whenever if or in is also specified, the all(), any() or none() option chosen will determine whether any, all or none of the observations satisfying the if and in conditions also satisfy the condition being tested. Note that if and in have otherwise no effect on the results of ds3.

The placeholder may be changed using placeholder().

Rule 6

The option detail specifies that a more detailed listing should be given. ds3, str d is equivalent to describe with all the string variables. ds3, num d is equivalent to describe with all the numeric variables.

Rule 7

The option cols() specifies the number of columns to be used in the listing. The default is 8. The number may be between 1 and 12, inclusive. Fewer columns than the default may be desired by those using many long variable names, and more by those using many very short variable names. cols() has no effect with detail.

Saved results

ds3 saves in r(varlist) the names of the variables listed.

Examples

All variables:

. ds3

. ds3, cols(6)

All string variables:

. ds3, str

. ds3, str d

. edit `r(varlist)'

All numeric variables:

. ds3, num

. order `r(varlist)'

. ds3, num

. su `r(varlist)'

All float variables:

. ds3, float

All variables that are not float:

. ds3, float co

All variables with value labels attached:

. ds3, has(vall)

All variables with the value label origin attached:

. ds3, has(vall origin)

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

. ds3, has(f d* t*)

Variables with left-justified string formats:

. ds3, has(f -*s)

Variables with right-justified string formats:

. ds3, str not(f -*s)

Variables with comma formats:

. ds3, has(f *c)

Variables with characteristics defined:

. ds3, has(c)

Variables with all values missing:

. ds3, all(missing(X))

Variables with any values negative:

. ds3, any(X < 0)

Variables with any nonsensical values:

. ds3 if male, any(X > 0 & X < .)

Author

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

Acknowledgement

Suggestions from Richard Goldstein, William Gould, Jay Kaufman and Fred Wolfe were very helpful in developing this program.

Also see

On-line: help for describe Manual: [R] describe, [R] saved results