Professional Documents
Culture Documents
Embrace Stata!
Stata is your statistical buddy!
If you put in a bit of effort to learn the
basics, you should find the program quite
easy and very helpful.
Statistical software can be very
intimidating your 1st time around. Stay
patient!
Review Window:
lists all commands
Click on command to
rerun
Variable
Window
Graph Window:
Click on graph & copy into
word doc
Command
File pathname
Variable
Name
This tells
STATA the
variable is
string
Summarizing data
list
print your dataset to the results window
summarize variable
prints summary stats in the results window
summarize variable, detail
provides additional summary statistics
Bar Charts
graph bar cigs, over(year) title("Cigarette Consumption Per Person, US")
b2(Year) ytitle("number of Cigarettes") ylabel(0(2000)4000)
Number of Cigarettes
2,000
4,000
1900
1910
1920
1930
1940 1950
Year
1960
1970
1980
1990
Box plot
graph box cigs, title("Cigarette Consumption per Person, US")
ytitle("Number of Cigarette")
graph box resident, medtype(line) box(1, fcolor(magenta)
lcolor(purple)) title(Box plot of Nursing Home Residents)
80
Histogram
histogram resident, ytitle(Distribution of Residents)
xtitle(Number of residents)
title(Histogram of the Distribution of Residents)
.005
Distribution of Residents
.01
.015
.02
.025
0.00
20.00
40.00
Number of residents
60.00
80.00
Save commands!
Open a do editor:
Window Do-file Editor New Do-File
Copy and paste commands in this file to save for later
use
You can also copy and paste commands into a simple txt
file or a word file
Please include important output (results & graphs) in
your homework, along with the commands that produced
the included output.
type "C:\Temp\myfile.log"
To run that file as a program (referred to as a "do-file" in Stata), you
can simply issue the Stata command:
do "C:\Temp\myfile.log"
Labels
Save organ.dta from the website to your computer, and it
open in Stata
The names of the afflicted organs are just labels. To see
what the raw data look like, you can list them without the
labels as follows:
list, nolabel
You can see what the association of label and value is by
listing the labels:
label list
sort organ
Then we can summarize the data by organ as
follows:
Bronchus
Ovary
Stomach
Breast
Colon
The first conclusion from the box plot is that women with breast
cancer have the longest survival. This is consistent with the
descriptive statistics produced by the summarize command.
generate lsurv=ln(survival)
label var lsurv "Log-transformed survival"
Bronchus
Colon
Ovary
Stomach
Total
Breast
Histograms by group
We can also generate the histograms of
survival time (log-transformed) for each
type of cancer as well as total as follows:
hist lsurv, freq by(organ, total)
Bronchus
Colon
Ovary
Stomach
Total
0
15
10
5
0
Frequency
10
15
Breast
Log-transformed survival
Graphs by Af f ected organ
If you dont like entering commands, you can also use the menus in
Stata to point and click your way through the analyses.
To summarize data:
Data Describe Data choose an option here
Graphs:
Graphics
Bar Chart
Histogram
Box plot
and many other options
This is a great way to explore the program, and learn about the
various capabilities of Stata