| Installing
Stata
Stata is free software for Dartmouth students. The current version
is version 9 for Windows XP and Mac OS X machines.
You can get the software from: www.dartmouth.edu/software
. Follow the link for your machine (Windows/Mac), and then choose
“Academic Software.” You’ll find Stata in the
list.
In order to run the software you need a supporting application
called KeyAccess. If you purchased
your computer through the college, all the necessary supporting
software should already be in place. If not, you’ll need to
install and configure KeyAccess before you can run Stata. Check
out “Using
KeyAccess to Activate Software” for help with this.
KeyAccess (KSClient) allows you to
run keyserved applications. Keyserved applications are those where
the server determines whether or not you’re authorized to
use the application. The Dartmouth keyserver address is keyserver.dartmouth.edu.
This must be set in the KeyAccess setup dialog.
Stuffit Expander is used by the Mac
download for expanding the installation package.
Stata will download as a Zip file for Windows machines and as
an Installer package on Mac machines.
For Windows users,
open Zip folder and run the stata9.msi file. When the installation
is complete, launch the program via START – All Programs –
Dartmouth College – Stata9 – Launch Stata9. You’ll
get a message saying the program is not licensed and then a dialog
box with a form to fill out. Using the information in the License.txt
file contained in the Zip folder, fill out the form and license
the program.
For Mac users, when
the download is complete, expand the package (this may happen automatically)
then click on the VISE icon labeled Stat 9.0 OX X Installer. Launch
the program by clicking on the Stata icon in the Stata folder in
the Applications folder of your Hard Drive.
If you have trouble please stop by the lab for help.
Stata
Windows
When you launch Stata, you’ll see several windows that you’ll
use while working with the program.
Command – provides
and input area for entering Stata command statements.
Results –
shows you the commands you’ve entered along with their results.
(If “more” appears at the bottom, press ‘enter’
to continue scrolling the results or ‘q’ to quit.
Review – displays
a history of the most recent commands entered. Highlighting a command
here will make it appear in the Command window.
Variables –
lists the variables contained in the current data set. Only one
data set at a time can be current in Stata. Highlighting a variable
in this window will make it appear in the Command window.
Data Editor –
displays the current data set in spreadsheet format. The data editor
can also be used when cutting and pasting data to and from other
spreadsheet applications like Excel. This window must be closed
in order to issue commands.
Graph – displays
the results of graphics associated command statements.
Stata Log Files
Log files keep a record of the command statements you enter and
Stata’s output. Specifying a filename saves the log to a file;
saving as a log format rather than the default SMCL format will
allow you to open the log in other applications (like Word).
A log file can be opened/started from the File - Log menu or with
the log command. The replace option overwrites the log file, append
adds to it. On or off option turns the logging on or off in the
middle of a session; close option closes the log file.
log using "c:\my documents\clients\hsb.log",
replace text
log off (you practice for a while,
not wanting to save all your mistakes)
log on (you turn the log back on so
you can save real work)
{It’s wise to open a log file at the beginning of a session,
turning it on or off as you need to save commands and results.}
Stata Data
Files
Stata can read the following filetypes:
.dta – a data file in Stata
format
.txt - data in ASCII (text) format
.raw – data in ASCII (text) format
.xls – a data file in Excel format
Different command statements are used to load data sets in different
file formats. Most commonly you’ll issue the use command to
read Stata formatted data sets.
File - Open menu will open a data
file already in Stata format
use opens a data file that is already
in Stata format. The directory path must be specified.
use "c:\my documents\clients\hsb.dta"
insheet will read (only) comma or tab-delimited
data; single line per observation.
insheet id sex race ses sctyp
hsp locus concpt mot car rdg wrtg math sci civ using ":Macintosh
HD:Desktop Folder:hsb2.raw"
infile will read freefield data and
tab- or comma-delimited data; can have multiple records
infile id sex race ses sctyp hsp locus
concpt mot car rdg wrtg math sci civ using ":Macintosh HD:Desktop
Folder:hsb1.raw"
infix will read fixed field data
infix id 1-3 sex 4-8 race 9-13 ses 14-18
sctyp 19-23 hsp 24-28 locus 29-33 concpt 34-38 mot 39-43 car 44-48
rdg 49-53 wrtg 54-58 math 59-63 sci 64-68 civ 69-73 using ":bananas:Users:ac:Desktop:hsb.txt"
{You can often cut and paste data from other applications into
Stata's data editor}
Data sets in Stata follow the format
where rows are cases/observations and columns are variables.
General Commands
clear - clears data out of memory.
search – searches Stata help
for matching strings. This allows you to find help on command statements
and return codes which appear alongside of error messages. If you
make a mistake with a Stata command, it may return an error message
along with a return code {for example, r(199)}. The search command
can be used to get a more detailed description of the return code.
search r(199)
generate – computes a new variable
based on an expression.
Basic Analysis Commands
tabulate - gets counts and percents
of subgroups for 1 or 2 variables. Summarize option gets summary
stats for subgroups.
tabulate race
tabulate sex ses
tabulate race ses, summarize(math)
summarize - calculates summary statistics
such as mean and standard deviation. Detail option gets more statistics
and percentiles. By option gets statistics for subgroups.
summarize rdg wrtg
by race: summarize rdg wrtg math, detail (note: race must be sorted
first)
correlate - displays the correlation
matrix for a list of variables. Means option gets summary stats
for each variable.
correlate rdg wrtg math sci civ
correlate rdg wrtg, means
regress – fits a linear regression
model of a dependent variable on a single predictor or set of predictors.By
the time you’re done with this class, you’ll know what
that means.
Graphs
graph bar – generates a bar
chart
histogram – generates a histogram
graph twoway – generates a
two variable scatterplot
graph pie – generates a pie
chart
Graphs do not get written to the log files. They must be saved
using:
File-Save Graph
|