|
|
|
||||
|
|
|||||
By now you know that we will not be showing all of the options for any of the commands.
. clear
edit
save
infile
insheet
. clear
The clear command clears out the dataset that is currently in memory. We need to do this before we can create or read a new dataset.
name midterm final Smith 79 84 Jones 87 86 Brown 91 94 Adraktas 80 84 |
. edit
The edit command opens up a spreadsheet like window in which you can enter and change data. You can also get to the 'Data Editor' from the pull-down 'Window' menu or by clicking on the 'Data Editor' icon on the tool bar.
Enter values and press return. Double click on the column head and you can change the name of the variables. When you are done click the 'close box' for the 'Data Editor' window.
. save grades
save grades, replace
The save command will save the dataset as grades.dta. Editing the dataset changes data in the computer's memory, it does not change the data that is stored on the computer's disk. The replace option allows you to save a changed file to the disk, replacing the original file.
. list
summarize
Let's list the contents and run some statistics on the new data set
. clear
The infile command is used to read data from an external ascii file. The names of the variables are given followed by the keyword using which in turn is followed by the name of the file. str10 is not a variable name but indicates that name is a string variable up to 10 characters long.
The ASCII file called ascii.raw that looks like this:
"Smith" 79 84 "Jones" 87 86 "Brown" 91 94 "Adraktas" 80 84
. clear
type spread.raw
insheet using spread.raw
list
The insheet command is used to read data from a file created by a spreadsheet or database program. The values in the file must be either comma or tab delimited. The names are included in the file.
The spreadsheet file called spread.raw that looks like this:
name,midterm,final Smith,79,84 Jones,87,86 Brown,91,94 Adraktas,80,84
. clear
edit
save grades
save grades, replace
list
summarize
clear
infile str10 name midterm final using ascii.raw
clear
insheet using spread.raw
The Stata Class Notes are available on the World Wide Web by visiting ...
http://www.ats.ucla.edu/stat/stata/notes/
The datasets ascii.raw and spread.raw can be loaded directly into Stata, over the
Internet, using the following commands:
infile str10 name midterm final using http://www.ats.ucla.edu/stat/stata/notes/ascii.raw
insheet using http://www.ats.ucla.edu/stat/stata/notes/spread.raw
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