|
|
|
||||
|
|
|||||
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
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.
. mkdir statacls
cd statacls
log using unit1, text
use http://www.ats.ucla.edu/stat/stata/notes/hsb1
The mkdir command creates a new directory where we can store all of our data and log files. The cd command stands for change directory, in this case, to change to the statacls directory. The log command starts a log file called unit1 that keeps a record of the commands and output during the stata session. The use command loads a Stata dataset into memory for use. We include the "http..." because the data resides on our web server and we are loading it into memory via the Internet.
hsb1 is a sample of 200 cases from the Highschool and Beyond Study (Rock, Hilton, Pollack, Ekstrom & Goertz, 1985). It includes the following variables: id female race ses schtyp program read write math science socst. You can see the names of the variables in Stata's 'Variables' window.
. summarize read math science
summarize read, detail
The summarize command displays basic descriptive statistics: n, mean, standard deviation, min and max. The detail option provides more descriptive statistics, including the variance, skewness, kurtosis, the median and other percentiles.
. univar read math science
The univar command displays basic descriptive statistics and the five number summary: min, 25th percentile, median, 75th percentile, and max.
. graph read
The graph command is used to create one and two dimensional graphs. When graph is used with a single variable, you get a histogram.
. correlate read write math
The correlate command displays a matrix of Pearson correlations for the variables listed.
. graph read math
This version of the graph command uses two variables and displays a scatterplot.
. tabulate ses
tabulate ses, nolabel
The tabulate command with one variable creates a frequency distribution table. Note that the nolabel option shows the numeric values of the variable instead of the "value label."
. tabulate ses
tabulate ses female, all
The tabulate command with two variables creates a two-way table or crosstabulation. With the chi2 option the command includes the chi-square value along with its p-value.
. help tabulate
help tab
search residual
help command followed by a Stata command brings up the on-line help system for that command. With help you must spell the name completely and correctly. The search command looks for the term in help files, Stata Technical Bulletins and Stata FAQs.
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
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.
. 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
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.
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