Exporting data from SPSS to Mplus – a simple step-by-step guide

Exporting data from SPSS (23) to Mplus (7.3) – a simple step-by-step guide

Exporting data from SPSS to Mplus is theoretically a simple process, but can still be a little more complicated than it should be. Various instructions exist all over the Web, but many of them forgo a couple of details that may not be obvious to novices. Here’s my reasonably fool-proof step-by-step guide.

      1. Open your data set in SPSS.
      2. (Optional): Remove unnecessary variables.
        1. In Variable View, remove all the variables you do not intend to export to Mplus for analysis. Note that Mplus does not handle strings in any way, only numeric variables.
        2. Save your data set under an alternative name to avoid overwriting your complete set.
        3. In Variable view, select all the names of the variables and copy-paste them somewhere safe (e.g., a text editor). Don’t rearrange the variables after this.
      3. Convert missing values to a value easy for Mplus to handle (e.g., -999).
        1. Click Transform – Recode into Same Variables. Select all your variables. Under Old and New Values, select “System-missing” as the old value and enter your selected value (e.g., -999) as the new value. Execute.
        2. Ensure that no other values are used in your data to indicate “missing” (e.g., 0 or -99 or user-missing). If necessary, convert those to the value you chose as well, similar to 3a.
      4. Save data in a format Mplus can conveniently read.
        1. Select “Tab delimited .dat” as the type.
        2. If you did not remove unnecessary variables at step 2, click Variables and select which variables you wish to save. Take careful note of which variables you are saving and their order (i.e., write them down somewhere).
        3. Uncheck “Write variable names to spreadsheet“.
        4. Under Encoding, select “Local Encoding” to avoid SPSS saving in Unicode. (If you forgot this step, you can also simply open the final .dat file in Mplus, remove the first few characters (the Byte Order Mark, “”), and save to replace – this is the only effect saving in Unicode has in this particular case)
        5. Save to intended location.
      5. Open and use the file in Mplus.
        1. Under DATA: in your Mplus syntax file, point to the correct directory and data file, e.g., “DATA: File is “C:/directory/subdirectory/datafile.dat”; “. Note that Mplus uses Unix-style forward slashes /, not the Windows standard \.
        2. Under VARIABLE: in your Mplus syntax file, list all the variables you exported from SPSS. You should have them written down in the correct order from step 2c or 4b, so just paste them here, e.g., “VARIABLE: NAMES ARE id gender bmi iq_t1 iq_t2 iq_t3 iq_t4;” NB. Variable names can be a maximum of 8 characters in Mplus, so you might have to creatively shorten them. Of course, there is no reason to use the same names you had for them in SPSS in the first place, so you can just pick whatever.
        3. Also under VARIABLE: , indicate the value you chose at 3a for your missing data, e.g., “MISSING ARE ALL (-999)”.
        4. Also under VARIABLE: , indicate which variables you intend to include in the particular model you are evaluating, e.g., “USEVARIABLES ARE gender iq_t1 iq_t2 iq_t3;”.
      6. Complete other parts of your syntax and enjoy running your analyses in Mplus.


An added note on decimal indicators: Mplus only accepts the period as a decimal indicator. If you are using SPSS with localization settings set to use the comma as the decimal indicator (as is the case in, e.g., Finland), you have two choices. You can either set SPSS to use periods as the decimal indicator in its output and data files (it will still obey OS rules for displaying data in the data view, i.e., you might still see commas while using it), OR you can replace all commas in the resulting .dat file with periods using Mplus or any text editor, before using the file in Mplus.

Share Button

Leave a Reply

Your email address will not be published. Required fields are marked *