Search
UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

OLD Stata Class Notes
For the most recent version,  see http://www.ats.ucla.edu/stat/stata/notes2/

About the Class Notes

Class notes are the scripts that are followed during the classes in Stata. Typically, they are projected on the screen in the front of the class. Students also received printed copies of the class notes so that they can try the commands at a later time. The Stata class notes do not contain any of the computer output. The class notes are not meant to be a Stata textbook or a reference manual. However, it is possible for individuals to use the class notes to help in learning Stata even if they don't enroll in the classes.

Data Files for the Class

You can download the datasets used in the Stata 1 & 2 Classes directly into Stata over the Internet. Use the following commands:

. net from http://www.ats.ucla.edu/stat/stata/notes
. net get data

You can also download the data files for the Stata, SAS, and SPSS classes as a Winzip file by clicking on cldata.zip

The Stata 1 Class

Stata is a powerful and yet easy to use statistical package that runs on Windows, Macintosh, and Unix platforms. This two-hour class designed for people who are just getting started using Stata. The class will involve demonstration of Stata commands for statistics, graphics, and data management. Students will also get a chance to try out Stata during the hands-on portions of the class.

Class Notes        

Quicktime Movies

Getting Started    

Download  

About the Dataset  

Download

Creating Your Own Datasets

Download

Create & Modify Variables 

Download

More Statistics         

Download

Let's Get Organized     

Download

About the Stata 2 Class

The Stata 2 Class is meant for students who have taken the Stata 1 Class or who have the equivalent knowledge. The Stata 2 Class is more concerned with computer and data management commands than with the statistical procedures. The two-hour class will combine demonstration and explanation along with hands-on practice.

Class Notes        
Splitting & Combining Files
Intro to Graphics 
I log, I do
Controlling Your Computer
Statistics Revisited
Searching for Help
Learning More about Stata
Exploring on your own, the Codebook for LA High School

Some Additional Class Notes

Printer Friendly Version

Click here for all of the class notes and extra resources in one file (for easy printing) 

Recommended Reading

The text we recommend to accompany the Stata 1 & 2 Classes is Statistics with Stata: Updated for Version 7 by Lawrence C. Hamilton, ISBN 0-534-39654-2. You can obtain this book directly from Stata Corporation


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


UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Class Notes
Getting Started


1.0 Stata commands in this unit

We begin by showing how some of the commands work. We will not be showing all of the options for any of the commands.

. cd
mkdir
use
summarize
univar
graph
correlate
tabulate
help
search

2.0 Demonstration and Explanation

Type in the commands at the same time as the class instructor. Don't worry if you fall behind. There will be time to catch up when we move on to the next unit in a few minutes.

2.1 Getting Started

. mkdir statacls
cd statacls
log using unit1, text
use http://www.ats.ucla.edu/stat/stata/notes/hsb1

. summarize read math science
summarize read, detail

. univar read math science

. graph read

. correlate read write math

. graph read math

. tabulate ses
tabulate ses, nolabel

. tabulate ses
tabulate ses female, all

. help tabulate
help tab
search residual

2.2 Closing the log file

The log command is now used to close the log file. You can view the log file, unit1.log, with any text editor or word processor or you can enter the type command:

. log close
type unit1.log

2.3 Copying Stata Output and Graphs to Word

A common thing that you might want to do is to copy your Stata output and/or graphs to Word.  You can see the Stata Frequently Asked Question How do I Copy Stata Output and Stata Graphs into Word? to learn more about this.

3.0 Try the commands on your own

. use http://www.ats.ucla.edu/stat/stata/notes/hsb1
summarize read write math
summarize read, detail
graph read
correlate read write math
graph read math
tabulate ses
tabulate ses, nolabel
tabulate ses female
tabulate ses female, chi2
help summarize
search homogeneity

4.0 Can You Answer These Questions?

  1. What is the mean and standard deviation of socst?
  2. How many Hispancs are in the sample?
  3. How many Hispanic females are in the sample?
  4. What is the correlation between read and science, read and socst?

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/

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


UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Class Notes
About the Dataset


1.0 Stata commands in this unit

Again, we will not be showing all of the options for any of the commands.

. list
describe
codebook
display
inspect

if exp qualifier
in range qualifier

2.0 Demonstration and Explanation

. list
list female ses read science

. list female ses read science if science==.
list female ses read science if ses=="high"
list female ses read science if ses==3

Logical operators used in Stata

    ~       not
    ==       equal
    ~=       not equal
    !=       not equal
    >       greater than
    >=       greater than or equal 
    <       less than
    <=       less than or equal
    &       and
    |       or



list female ses read math in 50/60
list female ses read math in f/10
list female ses read math in -10/l

. describe

. codebook
codebook female ses race

. inspect female ses race

. summarize math
display 9.368^2

2.2 Remarks about if and in qualifiers

The if and in qualifiers work with almost all Stata commands. See how these commands from Unit 1 work with the qualifiers.

. summarize read write math if ses==3
correlate read write math in 50/150
graph read math if female==0
tabulate ses if read>50
tabulate ses female in 1/60

3.0 Try the commands on your own

. list
list female ses read science
list female ses read science if science==.
list female ses read science if ses=="high"
list female ses read science if ses==3
list female ses read science in f/10
list female ses read science in -10/l
describe
codebook female ses race
display 27.8^3.2
display (57.5 - 52.23)/10.25294

4.0 Can you answer these questions?

  1. What cases have a math score greater than 71?
  2. What is the race for those cases in which science is missing?
  3. What can you find out about the variable schtyp?
  4. What is two to the tenth minus one?

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/

Note: The dataset hsb2.dta is the same as hsb1.dta but without the missing data for science or the race values coded 5.


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


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


UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Class Notes
Create and Modify Variables


1.0 Stata commands in this unit

. generate
replace
recode
egen

2.0 Demonstration and Explanation

2.1 Create and modify variables

. use hsb2, clear
generate total = read + write
summarize read write total
generate total = read + write + math

replace total = read + write + math
. summarize read write math total

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

2.2 Egen

. egen zread = std(read)     * standard scores for read
list read zread
summarize read zread

egen rmean = mean(read), by(ses)     * mean read for each ses
list ses read rmean

egen mread = median(read), by(prog)     * median read for each prog
list prog read mread

egen rread = rank(read)     * rank for read
list read rread

Egen Functions

    count       number of non-missing vlaues
    diff       compares variables, 1 if different, 0 otherwise
    fill       fill with a pattern
    group       creates a group id from a list of variables
    iqr       interquartile range
    ma       moving average
    max       maximum value
    mean       mean
    median       median
    min       minimum value
    pctile       percentile
    rank       rank
    rmean       mean across variables
    sd       standard deviation
    std       standard scores
    sum       sums



3.0 Try the commands on your own

. generate tot = read + write + math
summarize tot
replace tot = read + math + science
summarize tot
generate newprog = prog
recode newprog 1/3=2 2=1
tabulate nprog
egen aread = mean(read),by(prog)
list prog read aread

4.0 Can you answer these questions?

  1. Create a new variable called gtot that weights the reading score 1.5 times as much as the math score.
  2. What is the mean and standard deviation of gtot?
  3. What do you think will be the result of this command, keep id read write?

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 dataset hsb2.dta can be loaded directly into Stata, over the Internet, using the following commands:
use http://www.ats.ucla.edu/stat/stata/notes/hsb2


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


UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Class Notes
More Statistics


1.0 Stata commands in this unit

. ttest
oneway
anova
test
regress
predict

2.0 Demonstration and Explanation

. use hsb2, clear

2.1 t-tests

. ttest write=50

. ttest write=read

. ttest write, by(female)
ttest write, by(female) unequal
sdtest write, by(female)

2.2 Analysis of Variance

. oneway write prog, tabulate
anova write prog
sort prog
by prog: summarize write
table prog, contents(n write mean write sd write)

. anova write female prog female*prog

2.3 Regression

. regress write read
regress write read, beta
predict pre1
generate pre2 = 23.95944 + .5517051*read
list pre1 pre2
graph pre1 write read, symbol(io) connect(L.)
graph pre1 write read, symbol(io) connect(L.) jitter(2)

. regress write read math
regress write read math female

2.4 Comments on anova & regress

3.0 Try the commands on your own

. use hsb2, clear
ttest math=50
ttest math, by(sch)
oneway math sci
oneway math prog
anova math prog ses prog*ses
test ses / prog*ses
regress science math
regress science math, beta
regress science math read
regress science math read write

4.0 Can you answer these questions?

  1. Could this sample have come from a population with a mean reading score of 53?
  2. Is there a significant difference in the means of low SES vs middle SES groups?
  3. Are the population means for social studies equals for all levels of SES?
  4. What is the regression equation for predicating social studies from reading and writing scores?

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 dataset hsb2.dta can be loaded directly into Stata, over the Internet, using the following command:
use http://www.ats.ucla.edu/stat/stata/notes/hsb2


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


UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Class Notes
Let's Get Organized


1.0 Stata commands in this unit

. order
rename
label data
label variable
label define
label values
replace
recode
note:
notes
save, replace

2.0 Demonstration and Explanation

Let's begin by using a new data set, schdat.dta, it looks like this:

id  a1  t1  gender  a2  t2 tgender
 1  95  88     0    94  95    1
 2  63  86     1    61  94    1
 3  87  80     0    81  84    1
 4  79  70     0    79  87    0
 5  68  78     1    63  69    0
 6  64  87     1    82  96    0
 7  86  75     0    69  76    0
 8  81  94     1    93  92    1
 9  89  79     0    90  78    1
10  78  68     1    80  80    1

. use schdat, clear
describe

2.1 ordering & renaming

. order id gender tgender a1 a2 t1 t2
rename a1 assign1
rename a2 assign2
rename t1 midterm
rename t2 final
rename gender female
rename tgender tfemale

2.2 Some labels

. label data "Fall 1999 Stat 100 Scores"
label variable female "student gender"
label variable tfemale "teacher gender"
generate totavg = (assign1 + assign2 + midterm + final) / 4
label variable totavg "total score, divided by 4"
describe

2.3 variable labels and recode

Let's make labels showing that female and tfemale are coded 1=female and 0=male.

label define sex 1 "female" 0 "male"
label values female sex
label values tfemale sex
describe
tab1 female tfemale
tab1 female tfemale, nolabel

The label define command creates a definition for the values 0 and 1 called sex. The label values command connects the values defined for sex with the values in female and tfemale.

. generate grade = totavg
recode grade 0/60=0 60/70=1 70/80=2 80/90=3 90/100=4
label define abcdf  0 "F" 1 "D" 2 "C" 3 "B" 4 "A"
label values grade abcdf
list grade totavg

The  generate and recode commands make a new variable grade going from 1 to 5. Using label define and label values the values of grade are labeled A - F.

2.4 Make a note of this

. note: gender is self-report
note: the final was a take-home exam
notes
save schdat2
use schdat2, clear

3.0 Can you answer these questions?

  1. Do you think that the variables midterm and final need variable labels?
  2. Type summarize. What do the means of female and tfemale mean?
  3. What would happen if you did not save your data after recoding and adding labels and notes? Is there any other way to keep track of everything you have done so far?

4.0 For More Information

5.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 dataset schdat.dta can be loaded directly into Stata, over the Internet, using the following command:
use http://www.ats.ucla.edu/stat/stata/notes/schdat


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


UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Class Notes
Splitting & Combining Files


1.0 Stata commands in this unit

. drop cases
keep cases
append
drop variables
keep variables
sort
merge

2.0 Demonstration and Explanation

2.1 Create two new datasets by dropping cases

. use hsb2, clear
drop if female==0
save hsbf

tabulate female

. use hsb2, clear
drop if female==1
save hsbm
tabulate female

2.2 Create two new datasets by keeping cases

The exact same thing can be accomplished using the keep command instead of the drop command.

. use hsb2, clear
keep if female==0
save hsbm, replace
tabulate female

. use hsb2, clear
keep if female==1
save hsbf, replace
tabulate female

2.3 Create a single dataset by appending

. use hsbm, clear
append using hsbf

. tabulate female

2.4 Create two new datasets by dropping variables

. use hsb2, clear
drop female-prog
sort id
save hsbv1
describe

. use hsb2, clear
drop read-socst
sort id
save hsbv2
describe

2.5 Create two new datasets by keeping variables

As before, the exact same thing can be accomplished using the keep command instead of the drop command.

. use hsb2, clear
keep id read-socst
sort id
save hsbv1
describe

. use hsb2, clear
keep id female-prog
sort id
save hsbv2
describe

2.6 Create a single dataset by merging

. use hsbv1, clear
merge id using hsbv2
describe

3.0 Try the commands on your own

. use hsb2, clear
drop if female~=0
save hsbf, replace
use hsb2, clear
drop if female~=1
save hsbm, replace
append using hsbf

4.0 Can you answer this questions?

  1. What would happen if you did the following?:
    use hsb2, clear
    append using hsb2

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 dataset hsb2.dta can be loaded directly into Stata, over the Internet, using the following commands:
use http://www.ats.ucla.edu/stat/stata/notes/hsb2


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


UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Class Notes
Intro to Graphics


1.0 Stata commands in this unit

. stem
graph

. kdensity
pnorm
rvfplot
rvpplot

2.0 Demonstration and Explanation

2.1 Stem-and-leaf Plots

. use hsb2, clear
stem math, lines(2)

2.2 The Graph Command

. graph math, histogram bin(11) normal
kdensity math, normal

. sort prog
graph math, box by(prog) total

. graph read math socst, box

. graph math, bar by(prog) means
graph read math socst, bar means

. graph math read science, oneway

. graph math read, twoway
graph math read, twoway oneway
graph math read, twoway box

. graph math read science ses, matrix half

2.3 Normal Probalility Plot

. pnorm math

2.4 Some Regression Related Plots

. regress math read science ses
rvfplot, yline(0)
rvpplot read, yline(0)
rvpplot science, yline(0)
rvpplot ses, yline(0)

3.0 Try the commands on your own

. use hsb2, clear
stem math, lines(2)
graph math, histogram bin(11) normal
sort prog
graph math, box by(prog) total
graph math read science, oneway
graph math read, twoway box
graph math read science ses, matrix half
pnorm math
regress math read science ses
rvfplot, yline(0)
rvpplot read, yline(0)
rvpplot science, yline(0)
rvpplot ses, yline(0)

4.0 Can you answer these questions?

  1. Can you determine graphically which of the following variables shows greater variability: read write math science or socst?
  2. Is the variables write normally distributed?
  3. Describe the relationship between socst and math for prog=3.

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 dataset hsb2.dta can be loaded directly into Stata, over the Internet, using the following command:
use http://www.ats.ucla.edu/stat/stata/notes/hsb2


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


UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Class Notes
I log, I do


1.0 Stata commands in this unit

. log using filename.log
log close
log off
log on
type
do

2.0 Demonstration and Explanation

2.1 The log Command, Example 1

. log using summary.log
use hsb2

generate lang = read + write
summarize read write lang
log close
type summary.log

2.2 The log Command, Example 2

. log using resid.log
use hsb2
regress read write math science
rvfplot
predict r, rstudent
sort r
log off
list r
log on
list if abs(r) > 2.5
log close

type resid.log

2.3 Using a do-file

Sometimes you may want to use the same commands on more than one file but you don't want to have to type them in more than once. Other times its easier to collect all of your Stata commands together in one place and do all at once rather than one at a time. A do-file allows you to place commands in a file and run them all at once. Any command that you can type in on the command line can be placed in a do-file.

Do-files are created with the do-file editor or any other text editor. Any command which can be executed from the command line can be placed in a do-file. Here are some commands that could be placed in a do-file:

set more off
use hsb2, clear
generate lang = read + write
label variable lang "language score"
tabulate lang
tabulate lang female
tabulate lang prog
tabulate lang schtyp
summarize lang, detail
table female, contents(n lang mean lang sd lang)
table prog, contents(n lang mean lang sd lang)
table ses, contents(n lang mean lang sd lang)
correlate lang math science socst
regress lang math science female
set more on

Let's look at a do-file that contains these commands that is on our floppy disk.

. type hsbbatch.do

Now let's "do" the file hsbbatch.do

. do hsbbatch

Notice that all of the commands scrolled off of the screen without prompting you with "-more-".  This is because we started the do-file with set more off.

2.4 A better do-file

The above do-file, hsbbatch did not save the results.  Let's improve it so it makes a log of its results.  The additions are shown in italics. Notice we start with capture log close to close the log (in case it was open) and then the log using command starts logging our results to hsbbatch.log.  

capture log close
log using hsbbatch.log, replace
set more off
use hsb2, clear
generate lang = read + write
label variable lang "language score"
tabulate lang
tabulate lang female
tabulate lang prog
tabulate lang schtyp
summarize lang, detail
table female, contents(n lang mean lang sd lang)
table prog, contents(n lang mean lang sd lang)
table ses, contents(n lang mean lang sd lang)
correlate lang math science socst
regress lang math science female
set more on
log close

Now let's "do" the file hsbbatch.do

. do hsbbatch

If we like, we could "run" the file hsbbatch.do and it would not show the results.

. run hsbbatch

Either way, we can see the results with the type command, i.e,

. type hsbbatch.log

4.0 Can you answer these questions?

  1. Can you create a do-file that does the following:
    a. computes frequencies for female and ses;
    b. computes descriptive statatistics for read, write and math;
    c. computes correlations between read, write, and math?

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 schdat.dta and hsb2.dta can be loaded directly into Stata, over the Internet, using the following command:
use http://www.ats.ucla.edu/stat/stata/notes/hsb2


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


UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Class Notes
Controlling Your Computer


1.0 Stata commands in this unit

. cd -- change directory
pwd -- print working directory
dir -- directory listing
ls -- directory listing
type -- type (display) a file to the screen
mkdir -- make a new directory
copy -- copy a file
erase -- erase (delete) a file

Many of these commands are similar to Unix or DOS commands.

2.0 Demonstration and Explanation

2.1 The pwd, dir & type Commands

. pwd
pwd
dir
dir *.do
ls *.raw
type hsbbatch.do
type ascii.raw
type cls2.log
type schdat.dta

2.2 The mkdir, copy & erase Commands

. mkdir stata2
copy hsb2.dta stata2\hsbnew.dta
cd stata2
dir
erase hsbnew.dta
dir
cd ..
pwd

3.0 Try the commands on your own

. pwd
dir
ls *.raw
mkdir ctata2
copy hsb2.dat stata2\hsbnew.dta
cd stata2
dir
erase hsbnew.dta
dir
cd ..

4.0 Can you answer these questions?

  1. Can you create a new directory, data, inside stata2?
  2. Can you make a copy of hsb2.dta in the data directory?
  3. Can you rename the copy of hsb2.dta to hisch.dta?

5.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 dataset hsb2.dta can be loaded directly into Stata, over the Internet, using the following command:
use http://www.ats.ucla.edu/stat/stata/notes/hsb2


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


UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Class Notes
Statistics Revisited


1.0 Stata commands in this unit

. tab1
tab2
ttest
hotel
regress
rreg
logistic
sw
xi
anova
signtest
signrank
ranksum
kwallis

2.0 Demonstration and Explanation

We haven't done any actual statistics in a while so let's try a few stat commands.

2.1 Stata Syntax

[by varlist:] command [varlist] [if exp] [in range] [, options]

2.2 Frequency tables

. use hsb2, clear
tabulate female race ses
tab1 female race ses

. tab2 female race ses

2.3 t-tests

. ttest write = read

. ttest write, by(female)

. ttest write, by(female) unequal

. hotel read write math, by(female)

2.4 Regression

. use hsb2
regress write read science female

. regress

. regress write read science female, robust

. rreg write read science female

. generate honcomp = (write >= 60) /* honors composition */
tabulate honcomp
logistic honcomp read science female
logit

. sw regress write read science female, pr(.05)

. sw regress write read science female, pe(.05)

. sw regress write read science female, pe(.05) pr(.1)

xi: regress math i.prog read
test Iprog_2 Iprog_3

xi: regress math i.prog*read
test Iprog_2 Iprog_3
test IpXrea_2 IpXrea_3

2.5 Analysis of Variance

. anova write prog female prog*female

. anova

. anova write prog female prog*female read, continuous(read)

. anova write prog female / prog*female /

. use spf
anova y b s, repeated(s)

. anova y a / s|a b a*b, repeated(b)

2.6 Nonparametric Tests

. signtest write = 55

. signrank write = read

. ranksum write, by(female)

. kwallis write, by(prog)

3.0 Try the commands on your own

. use hsb2
tab1 female race ses
tab2 female race ses
ttest read = write
ttest read, by(female) unequal
hotel read write math, by(female)
anova read prog ses prog*ses math, continuous(math)
anova read prog ses / prog*ses /
use spf
anova y b s, repeated(s)
use hsb2
regress read write science female, robust
rreg read write science female
sw regress read write science female, pr(.05)
xi: regress read write female i.ses i.prog
signtest read = 55
signrank read = write
ranksum read, by(female)
kwallis read, by(ses)

4.0 Can you answer these questions?

  1. What Stata command would you use to deciding between the equal variance t-test and the unequal variance t-test?
  2. When would you choose to use the ranksum procedure instead of the t-test.
  3. What happens when you type regress without any arguments after doing an anova?

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 hsb2.dta and spf.dta can be loaded directly into Stata, over the Internet, using the following commands:
use http://www.ats.ucla.edu/stat/stata/notes/hsb2 use http://www.ats.ucla.edu/stat/stata/notes/spf


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


UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Class Notes
Searching For Help


1.0 Stata commands in this unit

. help
search
tutorial

2.0 Demonstration and Explanation

2.1 Help

. help if
help anova
help regress
help regression

2.2 Search & Webseek

. search if
search regression
search ttest, manual
search tukey
search gould, author
search gould, author stb
search gould, author faq
net search missing data
findit missing data

2.3 Tutorial

. tutorial
tutorial regress

2.4 Stata Learning Modules

3.0 Try the commands on your own

. help if
search if
help regress
help regression
search regression
search ttest, manual
search Tukey
search gould, author
search gould, author stb
search gould, author faq

4.0 Can you answer these questions?

  1. How many STB articles have been written concerning regression?
  2. How many STB articles have been written by Bill Sribney?
  3. What happens when you do help ancova? What happens when you do search ancova? Why is there a difference?

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/

1 Jul 1999 - pbe


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


UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Class Notes
Learning More about Stata

ATS Web Pages

ATS has created a variety of web pages to help you learn and use Stata.  The web pages are located at http://www.ats.ucla.edu/stat/stata/

The pages include information about

The Stata page at http://www.ats.ucla.edu/stat/stata/ also has a search engine to help find relevant pages for you.We recommend searching using one word searches, choosing a word that most distinguishes your question.

Consulting Services

If you visit our main page at http://www.ats.ucla.edu/stat/ you can see the section about our Consulting Services, and see our consulting schedule and how to visit us at Walk In consulting and send us questions via email.

We are constantly updating our pages.  If you would like to receive occasional email notices notifying you of updates to our web pages and announcements of our Stata Classes, visit http://www.ats.ucla.edu/cfapps/listserv/joinleaveform.cfm and join the ATSstat-L list.

Searching the Internet

If you don't find what you want there, you can search the internet for information about Stata using a search engine like http://www.google.com or http://www.altavista.com .  With our ATS web pages, we recommend using one word searches, however when searching the entire internet you will usually get thousands (or even millions) of pages if you search just for a single word.  Here are some example searches that we can run in http://www.google.com which finds pages that have ALL of terms given.  (Many/most other search engines find pages that have ANY of the terms you supply, and it is often necessary to place a + in front of every term to request pages that have ALL of the terms, e.g. +Stata +regression +logistic).


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


UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Class Notes

Codebook for LA High School Data


Stata command to read data:

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

Some Research Questions:

  1. What does the overall data look like?
  2. What is the demographic composition of this sample?
  3. Do the demographics vary by school?
  4. What do the test scores look like?
  5. Do the schools differ on the test scores?
  6. Do the schools significantly differ on the test scores?
  7. Are absences related to other variables?

Codebook

Variable NameVariableValues
idStudent ID
number
Each student has a unique four digit ID number
Records from school Alpha begin with 1
and records from School Beta begin with 2
genderGender1 = Female
2 = Male
ethnicEthnicity1 = Native American
2 = Asian
3 = African-American
4 = Hispanic
5 = White
6 = Filipino
7 = Pacific Islander
schoolSchool1 = School Alpha (n=159)
2 = School Beta (n=157)
mathprCTBS Math
PR Score
percentile rank
langprCTBS Lang
PR Score
percentile rank
mathnceCTBS Math
NCE Score
NCE1 Score
langnceCTBS Language
NCE Score
NCE1 Score
bilingBllingual Status0 = No Bilingual Status (Native English Speaker)
1 = IFEP (Foreign language spoken in home but student tested English Proficient)
2 = RFEP (Formerly LEP but transitioned to English)
3 = LEP (Currently in Bilingual Program)
daysabsNumber of days
absent
Number of days

1NCE stands for normal curve equivalent. It's a type of standardized score with mean=50 and standard deviation=21.06.


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


30Sep99