Introduction to Stata

advertisement
Labs for Weil, Economic Growth: Introduction to Stata
Introduction to Stata
This guide provides a brief introduction to Stata for students who have never used this program
but are familiar with the operations of a Windows computer. There are many free Stata tutorials
available on the Internet and users who would like a more comprehensive introduction to Stata
can find them by typing “Stata tutorial” into a search engine like Google. This handout assumes
that students have access to Stata 8 on a Windows platform. Although Stata on a Mac platform
works similarly, previous versions of Stata are significantly different.
Stata files
Before starting work in Stata, it is important to learn that there are three kinds of files in Stata:
data files (which contain the data you are working with), log files (which contain the results of
your Stata session), and graphics files (which contain the results of any graphs you have saved).
Once you open up a log file, Stata automatically saves the results that you see on your screen as
you work in Stata, HOWEVER, Stata does not automatically save changes to your data or graphs
that you make. YOU MUST SAVE THESE FILES SEPARATELY IF YOU WOULD LIKE TO
RETURN TO THEM LATER.
To save all your work, there are three important things to remember:
1.
2.
3.
To save data files in Stata, use the Save command under the File menu or click on the
floppy disk icon in the tool bar.
To save graph files in Stata, you must use the Save Graph command under the File
menu or right click on the graph and select Save. You can also copy and then paste
a graph into your word processing program by right clicking on it, but this does not
allow you to later view your graph in Stata and make changes to it.
If you would like to save your results, you need to open a log file BEFORE you start
your work. To open a log file, click on the scroll icon in the tool bar. If you save
your log file as a .log file, you will later be able to copy and paste some of your
results into a word processing program. You must open a log file at the beginning of
your session to save your work. Once the results scroll off the screen, they cannot be
retrieved unless you are sending them to a log file.
Stata Basics
Stata is a very powerful statistical analysis program. However, it is easy to use: everything
that you do in this class can be done from the menus provided. Scroll over the menus and
you can see the many different calculations that Stata will perform for you. The labs contain
instructions for special operations you may need to complete specific labs, but this guide will
review a few of the basic operations you will use in most labs: generating new variables,
obtaining summary statistics, and graphing.
To work through the directions below, download the Stata data set for the first lab and open it
up on your computer. When you double click on a Stata data set, Stata will automatically
open for you. Remember, if you would like to save the results of your work, you must first
open up a log file.
1. Generating New Variables. To generate new variables in Stata, look under the Data
menu: >Data>Create or change variables>Create new variable. A dialog box will appear.
Type in the name of the new variable in the box following “Generate variable:” and then type
1
Labs for Weil, Economic Growth: Introduction to Stata
in a formula for the new variable you would like in the box following the “=” sign. Note that
a valid variable name in Stata does not contain any spaces or special characters like #, % or
&. Also, be aware that Stata is case sensitive. If you use capital or small letters in your
variable names, you will always need to refer to the variables in this way later. You can type
in complex formulas in this dialog box, just be sure to put the parentheses in the right place.
For example, RGDPPC00-(RGDPPC60/RGDPPC60) does not give the same answer as
(RGDPPC00-RGDPPC60)/RGDPPC60. If you do not put the same number of right and left
parentheses in, Stata will return an error when you try to create a formula.

Generate a new variable that shows how much real per capita income has changed from
1960 to 2000 for each country. Call this variable CHANGE.
2. Obtaining summary statistics. Stata easily provides averages, standard deviations,
minimums and maximums for any variable you request. To obtain this, go to the Statistics
menu: >Statistics >Summaries, tables & tests>Summary Statistics >Summary Statistics. If
you would like summary statistics for all of the variables in your data set, simply hit enter
when the dialog box appears. If you would like summary statistics for only some of the
variables in your data set, type in their names in the box following “Variables:”, leaving
nothing but a space between variables if you have more than one.

Determine the mean, minimum and maximum of the variable you created, CHANGE.
3. Graphing. Several different kinds of graphs are available in Stata under the Graphics
menu. One graph that we will be using often is the Scatter plot. To make a scatter plot,
go to the Graphics menu: >Graphics>Easy graphs >Scatter plot. A dialog box will
appear. Type in the name of the variable you would like to be on the X axis in the box
following “X variable” and the name of the variable you would like to be on the Y axis in
the box following “Y variable”. Note that the tabs in the dialog box will allow you to
change options in the graph, including adding titles and axes labels.
Other types of graphs in Stata can be made easily by choosing a graph type other than Scatter plot
from the Easy graph menu. You can easily copy and paste the graph into a word processing
document by right clicking on the graph and selecting copy and then pasting it into your word
processor. If you would like to view the graph in Stata later, you must also save the graph.

Make a scatter plot showing the relationship between RGDPPC60 vs. RGDPPC00.
Before you end your Stata session, you will usually want to save the changes that you made to
your data. If you have opened a log file, it is saved automatically by Stata and you do not need to
save it separately. If you would like to view your graphs in Stata later, you must also save those
before you exit.
2
Download