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.
- Open your data set in SPSS.
- (Optional): Remove unnecessary variables.
- 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.
- Save your data set under an alternative name to avoid overwriting your complete set.
- 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.
- Convert missing values to a value easy for Mplus to handle (e.g., -999).
- 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.
- 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.
- Save data in a format Mplus can conveniently read.
- Select “Tab delimited .dat” as the type.
- 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).
- Uncheck “Write variable names to spreadsheet“.
- 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)
- Save to intended location.
- Open and use the file in Mplus.
- 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 \.
- 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.
- Also under VARIABLE: , indicate the value you chose at 3a for your missing data, e.g., “MISSING ARE ALL (-999)”.
- 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;”.
- 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.