| Previous: estsimp | Up: The Main Commands | Next: simqi |
setx
setx function [weight] [if exp] [in range] [, noinher nocwdel]
setx varname1 function1 varname2 function2 ...
[weight] [if exp] [in range] [, noinher nocwdel]
setx (varname1 varname2) function1 (varname3 varname4) function2 ...
[weight] [if exp] [in range] [, noinher nocwdel]
where
function = mean|median|min|max|p#|math|#|`macro'|varname[#]
Description:
After simulating parameters from the last estimation (see Section
8.1), use setx to set values for the explanatory
variables (the
's), change values that have already been set, or
list the values that have been chosen. The main value types are
| mean | arithmetic mean |
| median | median |
| min | minimum |
| max | maximum |
| p# | #th percentile |
| math | a mathematical expression, such as 5*5 or sqrt(23) |
| # | a numeric value, such as 5 |
| `macro' | the contents of a local macro |
| [#] | the value in the #th observation of the dataset |
If you used multiply imputed datasets at the estimation stage, setx will use those same imputed datasets to calculate values for the explanatory variables. For instance, setx x1 mean would calculate the mean of x1 across all the imputed datasets.
When using setx or any other Stata command to calculate summary statistics such as means, medians, minimums, maximums, and percentiles, it is important to define the sample. At the estimation stage, Stata automatically disregards observations that do not satisfy the ``if'', ``in'', and ``weight'' conditions specified by the user. It also ignores observations with missing values on one or more variables. Before setting a particular variable equal to its mean or any other summary statistic, users must decide whether to calculate the statistic based only on observations that were used during the estimation stage, or to include other observations in the calculation.
By default, setx inherits the if-in-weight conditions from estsimp and disregards (casewise-deletes) any observation with missing values on the dependent or explanatory variables. You can specify different if-in-weight conditions by including them in the setx command line, and you can disregard all inherited conditions by using the noinher and nocwdel options described below.
The setx command is also used by another statistical package
called relogit, which is also available from
http://gking.harvard.edu. If you are running relogit
with the wc() or pc() options, indicating that the
data were selected on the dependent variable, setx will
correct the selection bias when calculating summary statistics. For
this reason, means and percentiles produced by setx may
differ from means and percentiles of the (biased) sample. When the
proportion of
's in the population is known only to fall within a
range, such as pc(.2 .3), setx will calculate bounds on the
values of the explanatory variables. The result will be two
-vectors, the first assuming that the true proportion of 1's is at
its lower bound, and the second conditional on the true proportion
being at its upper bound. The program will pass these vectors to
relogitq and use them to calculate bounds on quantities of
interest. To set each explanatory variable at a single value that
falls midway between its upper and lower bounds, use the
nobound option that is described below.
setx relies upon three globals: the matrix mrt_xc and the macros mrt_vt and mrt_seto. If you change the values of these globals, the program may not work properly.
setx accepts aweights and fweights. It also accepts the special options listed below.
Notes: (1) Setx will not accept spaces in mathematical expressions unless you enclose the expression in parentheses. setx x4 ln(20) is a valid command, but setx x4 ln( 20 ) is a syntax error. Similarly, setx x4 5*5 and setx x4 (5 * 5) are valid, but setx x4 5 * 5 is not. (2) You may use square brackets ([]) when referring to observation numbers, e.g. setx x [15], but do not use square brackets in mathematical expressions, or you may get unexpected results. We recommend that users check the values they have set with setx by entering setx without any arguments. (3) setx relies on three globals: the matrix mrt_xc and the macros mrt_vt and mrt_seto. If you change the values of these globals, the program may not work properly.
Options:
Examples:
To list values that have already been set:
. setx
To set each explanatory variable at its mean:
. setx mean
To set each explanatory variable at its median, based on a sample in
which
and all inherited conditions are ignored and casewise
deletion is suppressed:
. setx median if x3>12, noinh nocw
To set each explanatory variable to the value contained in the 15th observation of the dataset
. setx [15]
The command can also set each variable separately. For instance, to set x1 at its mean, x2 at its median, x3 at its minimum, x4 at its maximum, x5 at its 25th percentile, x6 at ln(20), x7 at 2.5, and x8 equal to a local macro called myval, type:
. setx x1 mean x2 median x3 min x4 max x5 p25 x6 ln(20) x7 2.5 x8 `myval'
To change the value of x3 from its previously chosen value to 5*5
. setx x3 5*5
To set all variables except x10 at their means, and fix
at its
25th percentile, call setx twice: once to set all variables
at their means, and a second time to change the value of
to its
25th percentile.
. setx mean
. setx x10 p25
setx can also set values for groups of variables. To set x1 and x2 to their means, x3 to its median, and x4 and x5 to their 25th percentiles, type:
. setx (x1 x2) mean x3 median (x4 x5) p25