-----------------------------------------------------------------------------------------------------------
help for System Variables manual: [U] 16.4 System variables (_variables)
-----------------------------------------------------------------------------------------------------------
System Variables
Expressions may also contain _variables (pronounced "underscore variables"). These are built in
system variables that are created and updated by Stata. They are called _variables because their
names all begin with the underscore '_' character.
The _variables are
[eqno]_b[varname] (synonym: [eqno]_coef[varname]) contains the value (to machine precision) of the
coefficient on varname from the most recently fitted model (such as ANOVA, regression, Cox,
logit, probit, multinomial logit, and the like). See [U] 16.5 Accessing coefficients and
standard errors for a complete description.
_cons is always equal to the number 1 when used directly and refers to the intercept term when used
indirectly, as in _b[_cons].
_n contains the number of the current observation.
_N contains the total number of observations in the dataset.
_pi contains the value of pi to machine precision.
_rc contains the value of the return code from the most recent capture command; see help capture.
[eqno]_se[varname] contains the value (to machine precision) of the standard error of the coefficient
on varname from the most recently fitted model (such as ANOVA, regression, Cox, logit, probit,
multinomial logit, and the like). See [U] 16.5 Accessing coefficients and standard errors for a
complete description.
The _n and _N variables are useful for indexing observations or generating sequences of numbers. _n
can act as a running counter within a by group and _N acts as the total number within each by group.
_rc is useful for programmers, particularly if you want to test a command internal to a program without having the program terminate.
Examples
. by famid: gen sibs = _N
. by famid: gen birtho = _N - _n + 1
. display _pi
. display cos(_pi)
. gen x = cos(_pi/4*_n)
. gen price2 = price[_n-1]
. mvreg len disp gear_ratio = turn tru mpg wei
. display [displ]_b[mpg]
. mlogit rep gear_ratio turn tru
. display [5]_b[turn]
Also see
Manual: [U] 16.4 System variables (_variables)
Online: help for by, generate, replace, subscripting