Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Introduction to STATA

Stata is a rich statistical software. In this session, we will learn a few basic tasks that can be done in Stata, such as
opening a dataset, investigating the contents of a dataset, using some descriptive statistics and making some
graphs. We will run through the session by using both menus and dialogs and Statas commands. The dataset we
use for this session is a set of data about vintage 1978 automobiles sold in the United States.
Stata Commands for todays lecture:
Log File:
Start a log file whenever you begin any serious work in Stata.
Stata Commands for todays lecture:
sysuse auto (for loading the auto dataset)
output, command window, review window, variables window
browse (to open data browser window)
value labels, missing values
describe
variable name, storage type, variable label, notes
summarize
make has no observations because it is a string variable. Rep78 has 5 missing values.
browse if missing(rep78)
tabulate rep78
tabulate foreign
tabulate rep78 foreign
count if foreign==1 & rep78==.
summarize mpg if foreign==0
summarize mpg if foreign==1
Compare gas mileage between foreign and domestic cars; foreign cars appear to have better gas mileage.
twoway (scatter mpg weight)
twoway (scatter mpg weight), by(foreign, total)
to see gallons per mile:
generate gpm=1/mpg
label variable gpm Gallons per Mile
twoway (scatter gpm weight), by(foreign, total)




Graphs:
Make a simple box plot that shows the displacements of the cars engines and how they compare across repair
records within the place of manufacture of the cars.
Graphics > Box Plot; Main Tab: displacement; Categories Tab, check Group1 and enter rep78, check Group 2 and
enter foreign. Submit! Titles Tab of the graph box dialog and add the title Displacement across Repairs within
Origin.
drop if rep78==.
graph box displacement, over(rep78) over(foreign)
graph pie, over(foreign)
graph bar displacement, over(rep78) over(foreign)
histogram weight, frequency
Use Stata Help
Do File Editor:
sysuse auto, clear
Use * to add comments
It is easy to import data from Excel!

You might also like