In the course of an analysis you may wish to save information from a given
model, for example, to use the output as the basis for a simulation in Mplus, or
to perform certain types of model diagnostics. The **savedata:** command allows the user to save information from a model
in a text file. This
information can then be used by Mplus, or read into another statistical package.
Unlike the output files, which are formatted for human readers, the files
created by **savedata:** are intended for Mplus or other programs to read,
thus results are often saved in a relatively unadorned text
format, and values are often in scientific notation. This page shows only a few of the **savedata:** options,
see the Mplus manual for a full listing of available **savedata:** options. In some cases more model specific
information can be saved, for example, one can request factor scores be saved
after a confirmatory factor analysis.

Mplus version 5.2 was used for these examples.

### 1.0 Saving the Data Used in Estimation

The

fileoption of thesavedata:command allows you to save the variables used in the analysis to a text file. All variables used in the analysis, including variables that are transformations of other variables, are saved. Categorical variables that have been recoded and weight variables that have been rescaled by Mplus are saved in their new form. Additional variables can be saved using theauxiliaryoption of thevariable:command. The name of the new file follows thefile isoption, in this case the file name isnewdata, with the extension.dat. If no extension is given then the file is produced without one. The input model below is a relatively simple path model, but this command is available for a variety of models. No changes to the model, other than the addition of thesavedata:command andfileoption, are necessary.

Title: Saving data used in estimation Data: file is /mplus/seminars/introMplus_part2/path.dat ; Variable: Names are hs gre col grad; Model: gre on hs col; grad on hs col gre; hs with col;savedata: file is newdata.dat;

Below is a portion of the output from the above input file. The omitted output is identical to the output from this model an otherwise identical model run without the

savedata:command because thesavedata:command does not change the model. Thesavedata:command dose result in some additional output at the very bottom of the output file (shown). Among other information, the additional output gives the order of variables in the new dataset, and the format they are saved in.

<output omitted> QUALITY OF NUMERICAL RESULTS Condition Number for the Information Matrix 0.348E-04 (ratio of smallest to largest eigenvalue)SAVEDATA INFORMATION Order and format of variables GRE F10.3 GRAD F10.3 HS F10.3 COL F10.3 Save file newdata.dat Save file format 4F10.3 Save file record length 5000

The file produced by the

fileoption of thesavedata:command contains one line for each case used to estimate our model. The first few lines of the filenewdata.datare shown below.

52.000 57.000 57.000 41.000 59.000 61.000 68.000 53.000 33.000 31.000 44.000 54.000 44.000 56.000 63.000 47.000 52.000 61.000 47.000 57.000 <output omitted>

### 1.1 Adding Measures of Influence to Saved Data

The log likelihood distance measure of influence, and/or Cook’s D can be requested in conjunction with the

fileoption of thesavedata:command. Includingsave = influence;orsave = cooks;adds the log likelihood (influence) and/or Cook’s D (cooks) measure of influence for each case to the file containing the data used in estimation (i.e. the file specified by thefile isoption). Below we have usedsave = influence cooks;to request both measures.

Title: Save data + ll distance + Cook's D Data: file is /mplus/seminars/introMplus_part2/path.dat ; Variable: Names are hs gre col grad; Model: gre on hs col; grad on hs col gre; hs with col; savedata: file is influence.dat;save = influence cooks;

Below is a portion of the output from the above input file. The output is similar to that from

savedata:with only the file option, except that two additional variables,outinflandoutcookare included in the saved dataset.

SAVEDATA INFORMATION Order and format of variables GRE F10.3 GRAD F10.3 HS F10.3 COL F10.3OUTINFL F10.3 OUTCOOK F10.3Save file influence.dat Save file format 6F10.3 Save file record length 5000

As with the previous example, the file

influence.datcontains one line for each case used to estimate the model. The first few lines of the fileinfluence.datare shown below. Note that the file now contains six variables (each in its own column), the four observed variables, plus two variables containing the value of the influence statistics for each case.

52.000 57.000 57.000 41.000 0.075 0.074 59.000 61.000 68.000 53.000 0.054 0.054 33.000 31.000 44.000 54.000 0.276 0.270 44.000 56.000 63.000 47.000 0.114 0.113 52.000 61.000 47.000 57.000 0.036 0.036

### 2.0 Saving Sample Statistics (Correlation and Covariance Matrices)

The

sampleoption of thesavedata:command saves a sample correlation or covariance matrix in a text file. By default a covariance matrix is produced if all of the variables are continuous, and a correlation matrix is produced if the variables are categorical or a mix of categorical and continuous. Thesampleoption both requests the additional output and specifies the name of the file, in this case,sampledata.dat. The input file below includes thesavedata:command with thesampleoption.

Title: Saving correlation and voariace matrices Data: file is /mplus/seminars/introMplus_part2/path.dat ; Variable: Names are hs gre col grad; Model: gre on hs col; grad on hs col gre; hs with col;savedata: sample is sampledata.dat;

The output associated with the

sampleoption of thesavedata:command is shown below.

SAVEDATA INFORMATION Sample/H1/Pooled-Within Matrix Save file sampledata.dat Save type COVARIANCE Save format Free

The entire contents of the file **sampledata.dat** is shown below. The
file contains two lines, each with values that appear in five columns, for a
total of ten values, which happens to be the number of unique
covariances/correlations in a matrix with four variables (recall that the number
of unique values in a covariance matrix is n*(n+1)/2 where n is the number of
variables). Note that the values are given in scientific notation.

0.89394375E+02 0.61236125E+02 0.11468097E+03 0.57706750E+02 0.68066850E+02 0.10459710E+03 0.54555125E+02 0.54488775E+02 0.63296650E+02 0.87328975E+02