UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Getting Started in Statistics with Stata


getting started

use http://www.ats.ucla.edu/stat/stata/notes/hsb2

describe

descriptive statistics / exploratory data analysis


summarize

summarize read write

summarize read, detail

tabulate prog, sum(read)

table prog, contents(n read mean read sd read)

stem read

graph read, hist bin(20)

graph read, box

frequency distributions & cross tabulation


tabulate read

tabulate prog

tabulate prog, nolabel

tab1 female prog ses

tabulate prog ses

tab2 prog ses female

by


sort prog

graph read, box by(prog)

by prog: summarize read write math

graph read,bar mean by(prog)

graph write,bar mean by(female)

sort female

graph write,bar mean by(female)

if


summarize read write math if ses=="high"

summarize read write math if ses=="3"

summarize read write math if ses==3

summarize read if ses==1 | ses==2

summarize read if ses~=3

summarize read if ses < 3

summarize read if female==2 & ses < 3

scatterplot & correlation


graph read write

graph read write, xlabel ylabel

graph read write, twoway box xlabel ylabel

correlate read write math science

graph read write math science, matrix half

creating and modifying variables


generate total = read + write

summarize total

replace total = total + math

summarize total

generate honors = .
replace honors = 1 if write >= 60 & write < 100
replace honors = 0 if write >= 0 & write < 60

tabulate honors

generate highses = ses
recode highses 3=1 1 2=0
tabulate highses

entering your own data

You can enter your own data using Stata's data editor. Let's enter the following data into the data editor.

Smith       79       84
Jones       87       86
Brown       91       94
Adraktas    80       84


clear

edit

save mydata

You can also enter data using a text editor or word processor. Below is a data file called tdata.raw. It was created using a text editor and saved "plain" ascii text.

-------------------------------tdata.raw-----------------------

"Smith"       79       84
"Jones"       87       86
"Brown"       91       94
"Adraktas"    80       84
"Johnson"     78       83
"James"       86       82
"Scott"       90       93
"Sanders"     79       83
"Henderson"   77       82
"Allen"       85       84
"Murphy"      89       92
"Jackson"     78       82

---------------------------------------------------------------

clear

copy http://www.ats.ucla.edu/stat/stata/notes/tdata.raw tdata.raw

infile str10 name midterm final using tdata.raw

save tdata

web notes

More Stata Class Notes are available on the World Wide Web by visiting ...
      http://www.ats.ucla.edu/stat/stata/notes/

The dataset hsb1.dta can be loaded directly into Stata, over the Internet, using the following command:
use http://www.ats.ucla.edu/stat/stata/notes/hsb1

Note: .dta is the extension for Stata-format files. Stata automatically includes .dta on files when they are saved. You do not have to include the .dta when reading datasets using Stata.


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.