|
|
|
||||
|
|
|||||
Data files for Mplus are just plain ASCII text files. With free format the values for each of the variables is separated by a delimiter, such as a blank or a comma. The example below contains the first 20 lines from a file called hsb.dat. The variables in the file are id, female, race, ses, schtyp, prog, read, write, math, science and socst.
70,0,4,1,1,1,57,52,41,47,57 121,1,4,2,1,3,68,59,53,63,61 86,0,4,3,1,1,44,33,54,58,31 141,0,4,3,1,3,63,44,47,53,56 172,0,4,2,1,2,47,52,57,53,61 113,0,4,2,1,2,44,52,51,63,61 50,0,3,2,1,1,50,59,42,53,61 11,0,1,2,1,2,34,46,45,39,36 84,0,4,2,1,1,63,57,54,58,51 48,0,3,2,1,2,57,55,52,50,51 75,0,4,2,1,3,60,46,51,53,61 60,0,4,2,1,2,57,65,51,63,61 95,0,4,3,1,2,73,60,71,61,71 104,0,4,3,1,2,54,63,57,55,46 38,0,3,1,1,2,45,57,50,31,56 115,0,4,1,1,1,42,49,43,50,56 76,0,4,3,1,2,47,52,51,50,56 195,0,4,2,2,1,57,57,60,58,56 114,0,4,3,1,2,68,65,62,55,61 85,0,4,2,1,1,55,39,57,53,46
The Mplus commands to read the data are shown below and are contained in a file named hsb.inp. The Title, Data and Variables command blocks are required. The Analysis command block is included so that we can check the data. We will go into this command block in more detail in the next unit.
Title:
Entering data example free format using hsb.dat
Data:
File is hsb.dat;
Variable:
Names are
id female race ses schtyp prog read write math science socst;
Usevariables are
id female race ses schtyp prog read write math science socst;
Analysis:
Type = basic;
The file fixed.dat contains ten observations with the data in fixed columns. Below the data the codebook for the data is given.
195 094951 26386161941 38780081841 479700 870 56878163690 66487182960 786 069 0 88194193921 98979090781 107868180801
codebook variable name column number id 1-2 a1 3-4 t1 5-6 gender 7 a2 8-9 t2 10-11 tgender 12 Fixed format data are handled using a FORTRAN type format statement in the Data command block. The Mplus commands are given in fixed.inp, shown below.
Title: Entering data example fixed format using fixed.dat Data: File is fixed.dat; Format is (3F2.0, F1.0, 2F2.0, F1.0); Variable: Names are id a1 t1 gender a2 t2 tgender; Usevariables are id a1 t1 gender a2 t2 tgender; Analysis: Type = basic;
If you are a Stata user, ATS has written a command, stata2mplus, that will convert a Stata dataset to an Mplus ASCII data file plus the necessary commands to read in the data. You can get the stata2mplus ado file by typing findit stata2mplus.
Here is the Stata command to convert the Stata dataset hsb2.dta to Mplus hsb2.dat and to create the input file hsb2.inp.
stata2mplus using hsb2 (highschool and beyond (200 cases)) Looks like this was a success. To convert the file to mplus, start mplus and run the file \hsb2.inp
And, here is the input file that was created. The command file contains more detail about the data file than our earlier example but all of the same command blocks are present. The "Analysis Type = basic ;" is included to allow you to run descriptive statistics in order to insure that the data were input correctly. We will cover descriptive statistics in the next unit.
Title:
Stata2Mplus convertsion for hsb2.dta
List of variables converted shown below
id :
female :
0: male
1: female
race :
1: hispanic
2: asian
3: african-amer
4: white
ses :
1: low
2: middle
3: high
schtyp : type of school
1: public
2: private
prog : type of program
1: general
2: academic
3: vocation
read : reading score
write : writing score
math : math score
science : science score
socst : social studies score
Data:
File is hsb2.dat ;
Variable:
Names are
id female race ses schtyp prog read write math science socst;
Missing are all (-9999) ;
Usevariables are
id female race ses schtyp prog read write math science socst;
Analysis:
Type = basic ;
Our second to last example on entering data is to enter a version of the hsb data that has missing data.
Below is the Stata code for reading the missing data file from ATS and converting it to an Mplus data file along with an Mplus input file (hsbmis.inp).
copy http://www.ats.ucla.edu/stat/mplus/seminars/IntroMplus/hsbmis.dta hsbmis.dta stata2mplus using hsbmis (highschool and beyond (200 cases)) Looks like this was a success. To convert the file to mplus, start mplus and run the file hsbmis.inp
The input file for this example is identical, except for the file name, to the previous example.
Our last example on entering data is entering data with a raw data file that has dots (.) to represent missing values. Say that you had a data file that was either comma separated, tab separated, or space separated where . was used to indicate missing values. You can read that as missing like in the example below, which reads the hsbmisdot.dat data file.
Title: Data: File is hsbmisdot.dat ; Variable: Names are id female race ses schtyp prog read write math science socst; Missing are .; Analysis: Type = basic missing;
The results of this are identical to the above example.
UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services