Mplus requires data to be read in from a text file without variable names, with numeric values only, and with missing data coded as a single numeric value, such as -999. A common workflow for preparing data to analyze in Mplus is to perform the variable cleaning in SPSS and then save the data as a text file. This guide shows the appropriate steps using the sample file
bollen_sem.sav data that can be downloaded from here.
First, open the data file in SPSS. You should see the following:
These data do not include any missing values, but if they did we could easily convert all variables to have missing coded as -999. To do so we would go to Transform \(\rightarrow\) Recode into Same Variables, and we would see the following dialog box:
Bring all of the variables over to the Numeric Variables box:
In the new dialog box, select System-missing under Old Value. Enter -999 in the Value field under New Value. Click Add so that you see the following:
Click Continue, then OK. The data are now ready to be saved.
Go to File \(\rightarrow\) Save As to open the Save Data As dialog box. By default, SPSS will save the file in native SPSS format with a .sav extension. Click the drop-down box to the right of the Save as type field and choose Tab delimited (*dat). Next, uncheck the box next to Write variable names to file. Finally, enter the name for the new data file, such as
sem-bollen. You should see the following:
There is one odd hiccup that occurs when you write the data from SPSS into a text file for Mplus. Without one final little adjustment, Mplus will not correctly read the data. To see this, open Mplus.
From inside Mplus, open the data file. This can be done by going to File \(\rightarrow\) Open… and navigating to the folder where you saved the data. By default, Mplus will only look for files with a
.out extension. In the lower right, next to the File name field, change to All Files (.). You will now see the data file with the
You can now open the file. When you do so, you will see an odd set of characters at the very start of the file (highlighted here).
Delete these to avoid odd results.
Click File \(\rightarrow\) Save. Now your data are ready.
One benefit of starting with SPSS is that you can go back into SPSS, choose the Variable View tab, and highlight the variable names to copy them and paste into an Mplus input file.
After highlighting the variable names, go to Edit \(\rightarrow\) Copy to save the variable names to the clipboard. Then return to Mplus and paste in the values. Mplus requires that you type out the names in the order in which the columns appear in the data file. This will place them in the correct order.
Now it’s just a matter of formatting and adding in the rest of the Mplus code. The following runs the model: