help usesome

Title

usesome -- Use subset of Stata dataset

Syntax

usesome varspec
[if] [in]
using filename
[,
options]

usesome
[if] [in]
using filename
[,
options
selection-options]

where varspec is

[varlist] [(numlist)] ...

and numlist refers to the positions of variables in the
dataset; negative numbers specify distance from the end of
the dataset. numlists must be enclosed in parentheses.

If filename is specified without an extension, .dta
is assumed. If filename contains embedded spaces, it must
be enclosed in double quotes.

clear replace the data in memory

nolabel do not load value labels

not load variables not specified in varspec

selection-options
has(spec) load variables that match spec;
see ds

not(spec) load variables that do not match spec;
see ds

insensitive perform case-insensitive pattern matching

findname(findname-options) load
variables returned by findname

Description

usesome is a convenience command for loading a subset of
a Stata dataset into memory. The command makes it easy to
specify variables ...

... referring to column positions in the dataset

... not to be loaded

... referring to properties (e.g., numeric variables)

usesome is mainly intended for use with flavors of Stata,
namely Stata BE (which was called Stata IC before Stata 17),
that cannot load the full dataset due to restricting the number
of variables.

Options

clear replaces the data in memory, even though the
current data have not been saved to disk; same as with use.

nolabel does not load value labels from filename;
same as with use.

not loads variables not specified in varspec from
filename.

Selection options

has(spec) and not(spec) select from filename
the subset of variables that meet or fail the specification
spec; see ds.

When specified for loading a subset of a dataset with more than
variables, has() and not() will be slow.

Although it is no longer shown in the syntax diagram, has()
and not() may be specified together with varspec and, if
they are, add to varspec all variables that meet or fail the
specification spec.

To select from varspec the subset of variables that meet or
fail the specification spec, specify
ds(has(spec) [insensitive]) or
ds(not(spec) [insensitive]).

insensitive specifies that has() and not() perform
case insensitive matching.

findname(findname-options) uses
community-contributed findname (Cox 2010a, 2010b, 2012, 2015, 2020)
to select variables by properties. Only options for selecting variables
are allowed. Option columns() is not allowed; variable column
positions should instead be specified in varspec.

Examples

Load the first three and last three variables from the auto dataset.

. usesome (1/3 -3/-1) using http://www.stata-press.com/data/r12/auto.dta , clear

Load all variables except foreign from the auto dataset.

. usesome foreign using http://www.stata-press.com/data/r12/auto.dta , clear not

Load all variables with value labels attached from the auto dataset.

. usesome using http://www.stata-press.com/data/r12/auto.dta , clear has(vallabel)

Saved results

usesome saves the following in r():

Scalars

r(k) number of variables in filename

r(chunks) number of varlists
(r(k)/)

Macros

r(varspec) varspec, fully expanded

r(varlist) variable names in filename
(if r(k) < )

r(varlist#) variables in the # chunk
of filename

References

Cox, N. J. 2020. Update: Finding variable names. Stata Journal
volume 20, number 4. (dm0048_4)

Cox, N. J. 2015. Update: Finding variable names. Stata Journal
volume 15, number 2. (dm0048_3)

Cox, N. J. 2012. Update: Finding variable names. Stata Journal
volume 12, number 1. (dm0048_2)

Cox, N. J. 2010a. Update: Finding variable names. Stata Journal
volume 10, number 4. (dm0048_1)

Cox, N. J. 2010b. Speaking Stata: Finding variables. Stata Journal
volume 10, number 2. (dm0048)

Author

Daniel Klein

klein.daniel.81@gmail.com

Also see

Online: use, describe, ds

if installed: findname, usedrop,
chunky, savesome