Get [M]oving in Mplus – part 5: Define subcommands

Despite having to import a dataset into Mplus from another stats program, you can conduct most of the variable manipulation you need in Mplus. This is good news as you’ll often find yourself in a position of having to transform exisiting variables (e.g., log transformations) or creating new variables (e.g., mean scores).

In any case, it can be very annoying having to go back to SPSS to do all of this stuff. Fret not, Mplus has your back with the DEFINE command.

There are a few notes to make before summarizing the most used operations under the DEFINE command.

  • Operations with the DEFINE command can be done on all observations or a selection of some based on conditional statements (e.g., IF(gender EQ 1) THEN…)
  • Transformations do not alter the original data (phew) but hold the alterations in memory only during analysis (unless you use the SAVEDATA command, then the transformed values are saved)
  • All statements in the DEFINE command are done in order (so if you create a mean score and want to transform it, it must be done in this order and not the opposite)
  • Any new variables you create for use in analysis must be listed after original variables being used in analysis within the USEVARIABLES subcommand.
  • The following logical operators, arithmetic operators, and functions can be used in the DEFINE command:

Screen Shot 2017-06-05 at 6.24.34 PM.png

And here are some of the common operations (although not an exhaustive list) you’ll likely find yourself using at one point or another:

Create mean score variables:

Love = Mean(intimate passion commit); 


Love = intimate+passion+commit/3;

Create summative score variables:

Love = Sum(intimate passion commit);

Create other variables (e.g., interaction terms or convert units such as kilos to pound)

Lust = intimate*passion;
Pounds = .454*kgs;

Grand- or group-mean center a variable or variables:




Standardize a variable or variables:


Transform variables:

Lovelog = log10(Love);
Lovesqrt = sqrt(Love);

Conditional statements:

IF (sex EQ 0 AND relstat EQ 1) THEN group = 1;
IF (sex EQ 0 AND relstat EQ 2) THEN group = 2;
IF (sex EQ 1 AND relstat EQ 1) THEN group = 3;
IF (sex EQ 1 AND relstat EQ 2) THEN group = 4;

If there are other operations that you need to do and are possible in the DEFINE command but I haven’t covered here, please let me know. If there are other operations I ever use along the way, I’ll be sure to update this post!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s