Introduction to Statistical Methods for the Life and Health Sciences
|
To start Stata, click on ``My Stata''
(found in the Items for Student folder).
When you start up Stata, 4 windows will pop up in addition to a menu bar.
The most important ones are the command window and the
results window.
You can enter data by hand or import it in from a file.
If manually entering data you'll be editing a text file containing
rows and columns of data.
Most of the datasets we'll use will generally be in proper
Stata format, a form that Stata knows how to read.
These files have names like filename.dta
(the .dta extension tells Stata that the file is
in Stata format).
Method 1: for use when the Stata object is on the
Internet at a known URL address. Type:
use http://www.ats.ucla.edu/stat/stata/wc/reg/elemapi.dta
The dataset is then ready for you to use Stata commands.
Method 2: for use when the Stata object is already on your hard drive.
Just double click on the Stata object you want to open.
Graphics in Stata
To construct a basic histogram for the variable varname, type:
graph varname
Remember the names of all currently used variables, which came with
the data set, or which you created, as stored in one of the additional
windows Stata provides. For example, to graph price, you would issue the command
graph price at the command window.
A graphics window should open up.
A useful option to the graph command allows you to change the number
of bars (``bins'') on the histogram (the default is 5):
graph price, bin(10)
where bin(10) specifies that you want to use 10 bins for this histogram.
You can choose a number different than 10 if you wish.
To create a box plot, type
graph price, box
at the command window. (We will learn more about this type of plot later.)
Basic Statistics in Stata
Here, generate some basic statistics (we will learn more about these later).
Try the commands:
summarize
and then
summarize, detail
Getting Help in Stata
Start to become comfortable using the help facilities
in Stata.
There are two useful commands: search and help for this.
To learn more about a specific concept (say you want to learn how to get
Stata to make a histogram), at the command window you could type
search histogram
(you could substitute other concepts for histogram, such as boxplot or
variance, etc.).
Usually several commands are displayed; you could decide which command
is likely to give you what you are most interested in.
To learn more about a specific Stata command (say you want more details about
the graph command), type
help graph
(you could substitute any Stata command for the graph command;
try it out for summarize for example).
Getting OUT of Stata
When you are done, after saving any work you might wish to use later
(see handout on saving your work in Stata), type
exit
in the command window or exit via the menu. Don't forget to logout afterwards.
Saving your work in Stata
While working in Stata, everything you type and all of your results
are displayed in the Results window. However, these results are NOT saved.
The window saves only 500 lines of output. After that, they are lost forever.
The ``Save'' and ``Save as'' commands save only variable definitions.
They do not save the output of any analyses.
There are a few different ways to save your work, but the most
straightforward is to cut and paste.
The cut and paste method works for saving both text and graphics for
later printing.
Cut and Paste Method for Saving Stata Output
1. Open up AppleWorks (or any other available word processor or text editor).
To do this while running Stata, you need to point your mouse at the menu
on the far upper right of the screen (it should now say ``Stata'')
and select Finder.
From there you can open the AppleWorks application, which is kept
in the ``Items for Students'' folder.
When it is running, you can switch between Stata and AppleWorks by
using this menu on the upper right or the screen.
2. From within Stata, select text with the mouse (click on text and drag
the mouse.) Then select ``Copy'' from the Edit menu (or hold down
the Apple and C keys at the same time).
3. Switch to AppleWorks. Open a new document (from the File menu).
Place the cursor on the page where you want to insert the copied text,
and click once.
Then select ``Paste'' from the Edit menu (or hold down
the Apple and V keys at the same time).
4. You can continue to do this as you produce results that you want to keep.
NOTE: You should NOT use the ``Save Graph'' or ``Save As'' option
in Stata to save graphs that you would like to print later from another
program (for example, a wordprocessing program such as AppleWorks).
These options create Stata-object graphs, which will only work if you wish to
view your graphs using Stata.
Everyone should
self-assess themselves.
And compare their work to the
template solution (this is not a unique solution, just a template)