Importing Data and Syntax Generator
Statistical Programs
Statistical Primers
Interfaces with SPSS, Excel, Ascii, SAS and STATA Formats
This page has two parts. The first part auto-generates R syntax you can execute that will import data from SPSS, SAS, STATA, or Excel and then create data files that are compatible with Mplus and R (you do NOT need to know R to use this syntax - just copy and paste it into R and it will do the rest; watch the video associated with importing). The second part (a) generates Mplus syntax that you can copy and paste into Mplus for when you do an Mplus analysis and (b) also creates syntax so you can read your data into R for use in lavaan or R more generally. See the 'Syntax' tab to learn about Mplus and R lavaan syntax.
Program Evaluation and Randomized Explanatory Trials
M-10
In this section, I import data for you and then output it in an Mplus compatible data file and an R compatible ASCII file. I generate R syntax here to accomplish the tasks. You will need to copy and paste the syntax I generate into the version of R on your computer and then execute it. If you do not have R on your computer, go to the 'Programs' tab on this website and click on the button 'Install R and libraries.' It will walk you through the process of installing it.

 
      
     
 
Click 'Choose File' and browse and open your R data file. Do this BEFORE generating the syntax
This section generates syntax that you can copy and paste to the Mplus or R input windows when you plan to analyze an SEM model. It creates all of the commands (including the variable names) except for the Mplus or lavaan model specification commands.
I assume you have already set up an ASCII type, space or tab delimited data file for use in R to conduct preliminary and supplementary analyses on the 'Programs' page of this website, or perhaps by using the first section of this page. The data file has the variable names in the first line followed by the data proper in subsequent lines. Browse and select this file below and I will then grab the variable names from it for use in the generated Mplus syntax. If the names are longer than 8 characters, I will truncate them, as required by Mplus.
Read the comments on the generated syntax. I added the comments to inform you about programming options.
You will need to make changes on both the Mplus syntax and the lavaan syntax commands that point to the name and location of the data file to read in.  In lavaan, I create a placeholder name in the generated syntax. If the Mplus syntax file and the data file are in the same folder, you do not have to specify the full path for the data file, just the name of the file and its tag.  I generate the Mplus syntax in the first box and the lavaan syntax below it. To see a diagram of your model after running it from Mplus, click on the menu item within the Mplus interface called ‘Diagram’ and then click on ‘View Diagram.’
Check to generate syntax without comments
Importing Data from Other Packages
Complete the information in the form below and then press the 'Create Syntax' button. Then copy and paste the generated syntax into R and run it. A data file will be created adding the letter M to the imported file name for the Mplus data and a second data file with the letter R added to it for the R data file. These files will appear in the same folder where you have your original data. For imported Excel files, I assume the first row has the variable names in it. If there are multiple sheets, specify the integer of the position of the sheet where the data and variable labels are (e.g., 1). Blank cells will be set to NA in the R data file (the R default). In the Mplus file, it will be set to the value you specify below for missing data. For SPSS, all system missing data (signified with a dot) will be treated as missing. You have the option of treating user-defined missing values, which are distinct from system missing, as missing (choose option 2) or instead passing the user-defined missing values as their original value (choose option 1). 
(For security, browsers do not allow me to access full path information. You will need to enter the full folder path after browsing to the file. Make note of the full folder path as you do so. Or click here for a shortcut tip)
The data files will be stored in the same folder as the imported data file
R Syntax to Import and Create Data Files
Syntax Generator
R Syntax for lavaan
To see a video of the process, click here
For a video of the process and instructions, click here.  Be sure to install the R libraries on the Program tab for this to work.