UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Class Notes
Creating Your Own Datasets


1.0 Stata commands in this unit

By now you know that we will not be showing all of the options for any of the commands.

. clear
edit
save
infile
insheet

2.0 Demonstration and Explanation

. clear

2.1 A small dataset

name      midterm   final
Smith       79       84
Jones       87       86
Brown       91       94
Adraktas    80       84 

2.2 Creating a dataset using the 'Data Editor'

. edit

. save grades
save grades, replace

. list
summarize

2.3 Creating a dataset from an ASCII file

. clear

net from http://www.ats.ucla.edu/stat/stata/notes/
net get data type ascii.raw
infile str10 name midterm final using ascii.raw
list
"Smith"       79       84
"Jones"       87       86
"Brown"       91       94
"Adraktas"    80       84

2.4 Creating a dataset from a spreadsheet or database

. clear
type spread.raw
insheet using spread.raw
list

name,midterm,final
Smith,79,84
Jones,87,86
Brown,91,94
Adraktas,80,84

3.0 Try the commands on your own

. clear
edit
save grades
save grades, replace
list
summarize
clear
infile str10 name midterm final using ascii.raw
clear
insheet using spread.raw

4.0 Can you answer these questions?

  1. What should you do when you get the following message after the command, use hsb2, "no; data in memory would be lost?"
  2. What is the difference between use grades and use grades, clear?
  3. What is the difference between save grades and save grades, replace?
  4. Consider the commands below:
    clear
    infile str10 name midterm final using ascii.raw
    insheet using spread.raw
    Do you think the "insheet" command will work? What should be done to make it work?

5.0 For More Information

6.0 Web Notes

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


How to cite this page

Report an error on this page

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


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.