帮助里面有介绍
Title
[U] 11.4 varlists
Description
A varlist is a list of variable names. The variable names in a varlist refer either
exclusively to new (not yet created) variables or exclusively to existing variables. A
newvarlist always refers exclusively to new (not yet created) variables. Similarly, a
varname refers to one variable, either existing or not yet created. A newvar always
refers to one new variable.
Sometimes a command will refer to a varname in another way, such as "groupvar". This is
still a varname. The different name is used to give you an extra hint about the purpose
of that variable. For example, a groupvar is the name of a variable that defines groups
within your data.
Examples include
myvar just one variable
myvar thisvar thatvar three variables
myvar* variables starting with myvar
*var variables ending with var
my*var variables starting with my & ending with var with any number
of other characters between
my~var one variable starting with my & ending with var with any
number of other characters between
my?var variables starting with my & ending with var with one other
character between
myvar1-myvar6 myvar1, myvar2, ..., myvar6 (probably)
this-that variables this through that, inclusive
The * character indicates to match one or more characters. All variables matching the
pattern are returned.
The ~ character also indicates to match one or more characters, but unlike *, only one
variable is allowed to match. If more than one variable matches, an error message is
presented.
The ? character matches one character. All variables matching the pattern are returned.
The - character indicates that all variables in the dataset, starting with the variable
to the left of the - and ending with the variable to the right of the - are to be
returned.
Many commands understand the keyword _all to mean all variables. Some commands default
to using all variables if none are specified.
Factor variables are extensions of varlists of existing variables. When a command allows
factor variables, in addition to typing variable names from your data, you can type
factor variables using factor-variable operators.
Factor variables create indicator variables from categorical variables, interactions of
indicators of categorical variables, interactions of categorical and continuous
variables, and interactions of continuous variables (polynomials).
There are five factor-variable operators:
Operator Description
------------------------------------------------------------------------------------
i. unary operator to specify indicators
c. unary operator to treat as continuous
o. unary operator to omit a variable or indicator
# binary operator to specify interactions
## binary operator to specify factorial interactions
------------------------------------------------------------------------------------
For complete syntax and usage of factor variables, see fvvarlist.
Time-series varlists are a variation on varlists of existing variables. When a command
allows a time-series varlist, you may include time-series operators. For instance, L.gnp
refers to the lagged value of variable gnp. The time-series operators are
Operator Meaning
---------------------------------------------------------
L. lag (x_t-1)
L2. 2-period lag (x_t-2)
...
F. lead (x_t+1)
F2. 2-period lead (x_t+2)
...
D. difference (x_t - x_t-1)
D2. difference of difference (x_t - 2x_t-1 + x_t-2)
...
S. "seasonal" difference (x_t - x_t-1)
S2. lag-2 (seasonal) difference (x_t - x_t-2)
...
---------------------------------------------------------
Time-series operators may be repeated and combined and both lowercase and uppercase
letters are understood. For more details, see help tsvarlist.
Examples
. webuse census4
. describe
These four regress commands are equivalent.
. regress brate medage medagesq reg2 reg3 reg4
. regress brate medage medagesq reg2-reg4
. regress brate med* reg2-reg4
. regress brate medage c.medage#c.medage i.region
. summarize _all
. sysuse citytemp
. describe
. summarize *dd
. summarize temp*
. summarize temp???
. summarize t*n
. webuse fvex
. describe
. regress y distance i.group
. regress y i.sex sex#c.distance
These two commands are equivalent.
. regress y distance i.sex i.group sex#group
. regress y distance sex##group