Defining New Variables
From the variables read via the DATA
command, new variables can be computed with the help of DEFINE
. This may be helpful, for instance, to create dummy variables, polynomials or interactions between variables.
IMPORTANT: Any new variable that is created with DEFINE
must be listed on the USEVARIABLE
subcommand after all variables that were read with DATA
.
Computations
Here is a simple example for a variable measuring the interaction between two variables, "educ" and "support":
DEFINE:
edusupp = educ * support;
As you may have guessed, the usual symbols for arithmetic operations apply. Use "**" for exponentation (as in a**2 for a squared). Expressions are, among others, LOG
, EXP
, SQRT
and ABS
.
Conditional transformations
You may use IF ... THEN statements, e.g., to create dummy variables.
DEFINE:
IF status EQ 2 THEN stat2 = 1;
IF status NE 2 THEN stat2 = 0;
Operators AND, OR or NOT may be used, and GT, GE, LT and LE are available in addition to EQ and NE. You may also use symbols such as "==" for EQ, "/=" for NE, ">=" for GE, and so on.
Cut
A variable with several values may be simplified, as it were, by creating fewer values the correspond to cutpoints. E.g.,
DEFINE:
CUT inc (1000 2000 3000 4000);
will result in variable inc
having five categories: Minimum value up to 1000; more than 1000 up to 2000; and so on.
© W. Ludwig-Mayerhofer, Mplus Guide | Last update: 14 May 2018