📄 egen.hlp
字号:
{pmore2}
produces the mode (within {it:varlist}) for {it:varname}, which may be numeric
or string. The mode is the value occurring most frequently. If two or more
modes exist, the mode produced will be a missing value. To avoid this, the
{opt minmode}, {opt maxmode}, or {opt nummode()} options may be used to
specify choices for selecting among the multiple modes. {opt minmode} returns
the lowest value, and {opt maxmode} returns the highest value.
{opt nummode(#)} will return the {it:#}th mode, counting from the
lowest up. Missing values are excluded from determination of the mode unless
{opt missing} is specified. Even so, the value of the mode is recorded for
observations for which the values of {it:varname} are missing unless they are
explicitly excluded, that is, by
{bind:{cmd:if} {it:varname} {cmd:< .} or {cmd:if} {it:varname} {cmd:!= ""}}.
{phang2}
{opt mtr(year income)}{p_end}
{pmore2}
may not be combined with {cmd:by}. It returns the U.S. marginal income tax
rate for a married couple with taxable income {it:income} in year {it:year},
where 1930 {ul:<} {it:year} {ul:<} 2004. {it:year} and {it:income} may be
specified as variable names or constants; e.g., {bind:{cmd:mtr(1993 faminc)}},
{cmd:mtr(surveyyr 28000)}, or {cmd:mtr(surveyyr faminc)}. A blank or comma
may be used to separate {it:income} from {it:year}.
{opth pc(exp)} [{cmd:, prop}]{right:(allows {cmd:by} {varlist}{cmd::}) }
{pmore2}
returns {it:exp} (within {it:varlist}) scaled to be a percentage of the total,
between 0 and 100. The {opt prop} option returns {it:exp} scaled to be a
proportion of the total, between 0 and 1.
{opth pctile(exp)} [{cmd:, p(}{it:#}{cmd:)}]{right:(allows {cmd:by} {varlist}{cmd::}) }
{pmore2}
creates a constant (within {it:varlist}) containing the {it:#}th percentile
of {it:exp}. If {opt p(#)} is not specified, 50 is assumed, meaning medians.
Also see {cmd:median()}.
{opth rank(exp)} [{cmd:,} [{opt f:ield}|{opt t:rack}|{opt u:nique}]]{right:(allows {cmd:by} {varlist}{cmd::}) }
{pmore2}
creates ranks (within {it:varlist}) of {it:exp}; by default, equal
observations are assigned the average rank. The {cmd:field} option calculates
the field rank of {it:exp}: the highest value is ranked 1, and there is no
correction for ties. That is, the field rank is 1 + the number of values
that are higher. The {opt track} option calculates the track rank of
{it:exp}: the lowest value is ranked 1, and there is no correction for ties.
That is, the track rank is 1 + the number of values that are lower. The
{opt unique} option calculates the unique rank of {it:exp}: values are ranked
1,...,{it:#}, and values and ties are broken arbitrarily. Two values that
are tied for second are ranked 2 and 3.
{phang2}
{opth rowfirst(varlist)}{p_end}
{pmore2}
may not be combined with {cmd:by}. It gives the first nonmissing value in
{it:varlist} for each observation (row). If all values in {it:varlist} are
missing for an observation, {newvar} is set to missing.
{phang2}
{opth rowlast(varlist)}{p_end}
{pmore2}
may not be combined with {cmd:by}. It gives the last nonmissing value in
{it:varlist} for each observation (row). If all values in {it:varlist} are
missing for an observation, {newvar} is set to missing.
{phang2}
{opth rowmax(varlist)}{p_end}
{pmore2}
may not be combined with {cmd:by}. It gives the maximum value (ignoring
missing values) in {it:varlist} for each observation (row). If all values in
{it:varlist} are missing for an observation, {newvar} is set to missing.
{phang2}
{opth rowmean(varlist)}{p_end}
{pmore2}
may not be combined with {cmd:by}. It creates the (row) means of the
variables in {it:varlist}, ignoring missing values; for example, if three
variables are specified and, in some observations, one of the variables is
missing, in those observations {newvar} will contain the mean of the two
variables that do exist. Other observations will contain the mean of all
three variables. Where none of the variables exist, {it:newvar} is set to
missing.
{phang2}
{opth rowmin(varlist)}{p_end}
{pmore2}
may not be combined with {cmd:by}. It gives the minimum value in {it:varlist}
for each observation (row). If all values in {it:varlist} are missing for an
observation, {newvar} is set to missing.
{phang2}
{opth rowmiss(varlist)}{p_end}
{pmore2}
may not be combined with {cmd:by}. It gives the number of missing variables
in {it:varlist} for each observation (row).
{phang2}
{opth rownonmiss(varlist)} [{cmd:,} {opt s:trok}]{p_end}
{pmore2}
may not be combined with {cmd:by}. It gives the number of nonmissing
values in {it:varlist} for each observation (row){hline 2}this is the value used
by {opt rowmean()} for the denominator in the mean calculation.
{pmore2}
String variables may not be specified unless option {opt strok} is also
specified. If {opt strok} is specified, string variables will be counted as
containing missing values when they contain "". Numeric variables will be
counted as containing missing when their value is "{ul:>}.".
{phang2}
{opth rowsd(varlist)}{p_end}
{pmore2}
may not be combined with {cmd:by}. It creates the (row) standard deviations
of the variables in {it:varlist}, ignoring missing values.
{phang2}
{opth rowtotal(varlist)}{p_end}
{pmore2}
may not be combined with {cmd:by}. It creates the (row) sum of the variables
in {it:varlist}, treating missing as 0.
{opth sd(exp)}{right:(allows {cmd:by} {varlist}{cmd::}) }
{pmore2}
creates a constant (within {it:varlist}) containing the standard
deviation of {it:exp}. Also see {opt mean()}.
{opt seq()} [{cmd:,} {opt f:rom(#)} {opt t:o(#)} {opt b:lock(#)}]{right:(allows {cmd:by} {varlist}{cmd::}) }
{pmore2}
returns integer sequences. Values start from {opt from()} (default 1) and
increase to {opt to()} (the default is the maximum number of values) in
{opt blocks} (default size 1). If {opt to()} is less than the maximum number,
sequences restart at {opt from()}. Numbering may also be separate within groups
defined by {it:varlist} or decreasing if {opt to()} is less than {opt from()}.
Sequences depend on the sort order of observations, following three rules: (1)
observations excluded by {help if} or {help in} are not counted,
(2) observations are sorted by {it:varlist}, if specified; and (3) otherwise,
the order is that when called. Note that no {it:arguments} are specified.
{opth skew(varname)}{right:(allows {cmd:by} {varlist}{cmd::}) }
{pmore2}
returns the skewness (within {it:varlist}) of {it:varname}.
When {opt skew()} is specified, {newvar} will always be produced as
{it:type} {opt double}. The {it:type} specified by the user will be ignored.
{phang2}
{opth std(exp)} [{cmd:,} {opt m:ean(#)} {opt s:td(#)}]{p_end}
{pmore2}
may not be combined with {cmd:by}. It creates the standardized values of
{it:exp}. The options specify the desired mean and standard deviation. The
default is {cmd:mean(0)} and {cmd:std(1)}, producing a variable with mean 0,
standard deviation 1.
{phang2}
{opth tag(varlist)} [{cmd:,} {opt m:issing}]{p_end}
{pmore2}
may not be combined with {cmd:by}. It tags just one observation in each
distinct group defined by {it:varlist}. When all observations in a group have
the same value for a summary variable calculated for the group, it will be
sufficient to use just one value for many purposes. The result will be 1 if
the observation is tagged and never missing, and 0 otherwise. Values
for any observations excluded by either [{it:{help if}}] or [{it:{help in}}]
are set to 0 (not missing). Hence, if {opt tag} is the variable
produced by {cmd:egen tag =} {opt tag(varlist)}, the idiom {opt if tag}
is always safe. {opt missing} specifies that missing values of {it:varlist}
may be included.
{opth total(exp)}{right:(allows {cmd:by} {varlist}{cmd::}) }
{pmore2}
creates a constant (within {it:varlist}) containing the sum of {it:exp}. Also
see {cmd:mean()}.
{title:Description}
{pstd}
{cmd:egen} creates {newvar} of the optionally specified storage type equal to
{it:fcn}{cmd:(}{it:arguments}{cmd:)}. Here {it:fcn}{cmd:()} is a function
specifically written for {cmd:egen}, as documented below or as written by
users. Note that only {cmd:egen} functions may be used with {cmd:egen}, and
conversely, only {cmd:egen} may be used to run {cmd:egen} functions.
{pstd}
Depending on {it:fcn}{cmd:()}, {it:arguments}, if present, refers to an
expression, {varlist}, or a {it:{help numlist}}, and the {it:options}
are similarly {it:fcn} dependent. Note that explicit subscripting (using
{cmd:_N} and {cmd:_n}), which is commonly used with {cmd:generate}, should not
be used with {cmd:egen}; see {help subscripting}.
{title:Examples}
{phang}{cmd:. egen avg = mean(chol)}{p_end}
{phang}{cmd:. gen dev = chol - avg}
{cmd:. egen medgro = median(inc80-inc79)}{right:({it:exp}, {cmd:-} means subtraction) }
{phang}{cmd:. egen avginc = rowmean(inc78 inc79 inc80)}{p_end}
{cmd:. egen avginc = rowmean(inc78 - inc80)}{right:({it:varlist}, {cmd:-} means through) }
{phang}{cmd:. egen taxrate= mtr(1978 inc78)}
{phang}{cmd:. egen stdscor = std(score)}{p_end}
{phang}{cmd:. egen newscor = std(score), mean(100) std(10)}
{phang}{cmd:. egen ttlsales = total(sales), by(region)}
{phang}{cmd:. egen racesex = group(race sex)}{p_end}
{phang}{cmd:. ir deaths smokes pyears, by(racesex)}
{title:Also see}
{psee}
Manual: {bf:[D] egen}
{psee}
Online: {helpb collapse}, {helpb generate}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -