0% found this document useful (0 votes)
113 views10 pages

Stata For Windows

Statistics, Stata, research

Uploaded by

rbmalasa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
113 views10 pages

Stata For Windows

Statistics, Stata, research

Uploaded by

rbmalasa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

February 2008

Using Stata for Windows


This document covers the basic features of Stata for Windows. Stata is a comprehensive and easy-to-
learn statistical application that contains most of the statistical tools and models developed in the
econometric literature. Stata contains procedures for managing, graphing, and analyzing data, as well as
certain procedures (such as Tobit regression, Heckman correction for sampling bias, and analyses of
sampling design effects) that are not available in other applications installed on the Stanford library
computers.
Stata for Windows is publicly available in the Meyer Library cluster and on designated computers (PCs
1 through 6) in the Jonsson Social Science Reading Room cluster in Green Library Bing Wing. To use
any of the public computers on campus, you must have a SUNet ID (Stanford University Network
Identifier). See the following URL for information on obtaining a SUNet ID:

http://www.stanford.edu/services/sunetid

Table of Contents
Getting Started with Stata for Windows ..................................................................................... 1
Stata Windows........................................................................................................................... 3
Working with Data Files ............................................................................................................. 4
Entering Data into Stata................................................................................................................................... 4
Opening Data Files.......................................................................................................................................... 4
Renaming and Labeling a Variable .................................................................................................................. 5
Saving Data Files ............................................................................................................................................ 5
Saving Output Files ......................................................................................................................................... 5
Saving Graphs................................................................................................................................................. 6
Analyzing Data .......................................................................................................................... 6
Using the Statistics Pull-down Menu ................................................................................................................ 6
Creating Charts and Graphs ............................................................................................................................ 7
Using the Command Syntax ............................................................................................................................ 8
Printing Files.............................................................................................................................. 9
For More Information and Assistance........................................................................................ 9
Stata Help ....................................................................................................................................................... 9
Stata Tutorials ................................................................................................................................................. 9
Stata Documentation and Books...................................................................................................................... 9
SSDS Software Services at Stanford ............................................................................................................. 10

Getting Started with Stata for Windows


Stata is a command and window-driven application. That is, it allows users to issue commands for
procedures and has a graphical interface consisting of pull-down menus, dialog boxes, and windows that
display and organize data, and perform numerical and graphical tasks. You can perform most tasks in
Stata by pointing and clicking the mouse. This section describes the basic features of the Stata pull-
down menus and windows. Previous versions of Stata require users to type out commands for most
procedures. For more information on executing Stata command files or earlier versions of Stata for
windows, please see Using Stata on the Leland Systems (UNIX).

Stanford University
Social Science Data and Software
A basic familiarity with the Windows operating system is all you need to get started with Stata. You can
access Stata on a PC from the Start menu, or by double-clicking on the Stata icon (shown below) on the
desktop if applicable.

When you start Stata, a screen like the one below will appear:

Results Window
Displays Previous
Commands

Lists all variables

Type
commands
here

Like most Windows programs, Stata has a toolbar and menu bar with pull-down menus that you can use
to access many of the features of the program. The toolbar contains buttons for more commonly used
procedures. To see what each button does, hold the mouse over the button for a moment and a
description of what the button does will appear. The following is a summary of the main pull-down
menus and their functions:

Menu Functions
Open and save data files, command files, and output (log) files.
File
Print files, and exit Stata.
Edit Modify or copy text, search for data or text, replace text.
Customize the look of the Stata window by selecting to view the
Prefs
status bar, toolbars, grid lines, and value labels. Change fonts.
Make changes to selected variables or compute new variables.
Describe data, Sort data, merge files, subset data, and make
Data
other global changes to Stata data files. Changes made are not
permanent until you save the data file.

2 - Using Stata 8 for Windows


Create charts and graphs such as scatterplots, bar charts, line
graphs, and pie charts. For more information on creating and
Graphs
editing charts and graphs, see Creating Charts and Graphs on
page 7.
Perform statistical procedures to produce descriptive and
Statistics
inferential statistics.
Allows advanced users to customize and expand Statas
User capabilities by adding user-definable menus. It remains empty
unless the user adds menus.
Window Bring a different Stata window to the foreground.
Get help on Stata procedures, commands, and connect to the
Help
Stata website for more help information.

Stata Windows
There are eight different types of windows in Stata. All of the windows are accessible from the pull-
down Window menu. The following is a summary of the functions and contents of the most windows.

The Results window displays the results of your analysis. This window appears when you launch Stata.
To bring this window to the foreground, click on the icon on the toolbar .

The Review window displays all of your previous commands. If you want to redo your analysis at a
later date, you can save the commands in the review menu by clicking on the upper left corner and
selecting Save Review Contents. This window appears when you launch Stata.

The Variables window displays all variables in your dataset. It can help you fill out the dialog boxes or
the Command window for Stata commands. By default, when you click on a variable in the window, it
will appear in a dialog box if open, and the command window if no dialog box is open. This window
appears when you launch Stata.

The Command window is where you type the command syntax to tell Stata to do things. It also appears
when you launch Stata. For more information on the syntax commands, see Using the Command
Syntax on page 8.

The Data Editor window displays the contents of your data file in a spreadsheet format. To view this
window, click on the spreadsheet button on the toolbar . You can create new data files by entering
data directly into the cells in the Data Editor window. You can also open existing data files and modify
them in the Data Editor window. You can only have one data file open at a time in Stata.

The Viewer is where you can see help information, look at logs of your Stata sessions, add new
commands from the internet, and install the latest updates from Stata. To view this window, click on the
eye button on the toolbar .

The Do-File window is where you can create text files of your commands. If you know that you will be
issuing many commands to Stata and that you will want to be able to reproduce your work, we

Using Stata 8 for Windows - 3


recommend that you create command files so that you have a record of what you have done. To bring
the Do-File editor to the foreground click on the icon on the toolbar .

The Graph window opens automatically when you create a graph. To bring a graph to the foreground
click on the graph icon on the toolbar .

Working with Data Files

Entering Data into Stata


There are several ways to enter data into the Stata Data Editor window. You can enter data directly into
cells in the Data Editor window, open an existing Stata for Windows or Macintosh file, or open ASCII
(or text) files.
To enter data directly into Stata, open the Data Editor window by clicking on the spreadsheet icon on
the toolbar . The Data Editor window consists of a grid of rows and columns. The rows correspond
to cases, and the columns correspond to variables.
Type values into the empty cells and use the mouse, arrow keys, or tab key to move from one cell to
another. For example, if you have data on the ages and heights of 100 children, begin by entering the
first childs name, age, and height in the first row. (See below for an example.) Then type the
information for the second child in the second row. When you have entered all of the data, you will have
a dataset with 100 rows and 3 columns. If you have missing values, leave the cell empty and Stata will
designate it a missing value by placing a period in the cell. Your data will look like this:

After you have entered the data and you are ready to exit the data editor, click the preserve button to
update the backup copy. Stata automatically makes a backup copy of your data when you enter the
editor. If you want to cancel the changes that you made and restore the backup copy, click on restore.

Opening Data Files


Opening an Existing Stata for Windows Data File
To work with an existing Stata for Windows or Macintosh data file, launch Stata and then select Open
from the File menu. In the dialog box that appears, highlight the data file you want to open and click on
Open. The data file will appear in the Data Editor window.
Note: By default, Stata allocates 1 megabyte of memory for data. If your data file is larger than this, you
need to set the memory to accommodate the size before you open the data. To do this, in the Command
4 - Using Stata 8 for Windows
window, type set memory followed by an overestimate of the size of your dataset. For example, if
your data is 5mb, you might type set memory 10m in order to allocate enough space for adding or
recoding new variables.
Opening Other Types of Data Files
Stata can import data from text (ASCII) files. To open an ASCII (or text) file in Stata, go into the File
pull-down menu and select Import. From the submenu, you can choose to import data created by a
spreadsheet, in fixed format, in fixed format with a dictionary, or unformatted. Once you select the
predefined format, in the dialog box that appears, select your file. You need to tell Stata how variables
are delimited or arranged, whether you have included variable names, and so on.
Stata can only read data in ASCII or Stata format. However, if you have data in a spreadsheet format
(e.g., Excel), you can copy and paste the data into the Data Editor. If you have data in another format
(e.g., SPSS, SAS), you will need to use data conversion software such as StatTransfer or DBMS/COPY
to convert your data into a Stata format. Data conversion information and software are available in the
Velma Denning Room (Room 120F in the Bing Wing of Green Library).

Renaming and Labeling a Variable


By default, Stata assigns the name var1" to the variable entered in the first column, "var2," to the
variable in the second column, and so on. It is a good idea to give variables more descriptive names,
such as "age" or "height." To change Stata default variables names, select Variable Utilities from the
Data menu and Rename Variable from the submenu. In the dialog box that appears, type the existing
variable name (e.g., var1) and the new variable name in the appropriate boxes and click OK. You will
see the change in the Variable window and in the Data Editor window.
You may also want to define missing values or assign value labels for your variables. To define missing
values, select Create or Change Variables from the Data menu and Other Variable Transformation
Commands from the submenu. Select Change Numeric Values to Missing and in the dialog box that
appears, specify the variable you want to change and the numeric value you want to set to missing. Then
click OK. You can also assign descriptive labels to the values of your variables by selecting Labels and
Notes from the Data menu and Assign Value Label to Variable from the submenu. Your label can be
as long as 80 characters (e.g., Height in cm, shoes off).

Saving Data Files


To save data you have entered into the Data Editor window, or to save the modifications you made to
your data (e.g., labels, added variables, etc.), select Save from the File menu. In the dialog box that
appears, type a name for your data file, select where you want to save it, and click on Save. Your saved
file contains all of the values you entered, as well as the names of your variables, the labels you assigned
to them, and any other formatting changes you made.
Note: Be aware that when you save your data, it overwrites the specified data file. Any variables or
cases that you have deleted or selected out will be lost. To retain the original file, click Save As instead
of Save in the File menu, and give the altered data a new name.

Saving Output Files


In order to save your output, you must open a log file that will record what you do and the results of
your analysis before you begin working in Stata. To do this, click on the log icon on the toolbar . In
the dialog box that appears, type a name for your data file, select where you want to save it, select to

Using Stata 8 for Windows - 5


save as type .log and click on Save. The file will save everything that you do on Stata from that point
on. To view or end your session, click on the log file icon again, and select the appropriate option from
the dialog box that appears. You can print the output by opening the viewer and clicking Print Viewer
from the File menu.
Note: It is a good practice to give different types of Stata files different extensions so they can be easily
distinguished from each other. The file extension .dta (e.g., example.dta) is by default added to Stata
data files, while .smcl (e.g., example.smcl) is added to Stata log files. If you want to be able to edit your
log file in a text editor, we recommend that you save it as a .log file instead.

Saving Graphs
Unlike SPSS for Windows and Macintosh, Stata displays and saves graphs separately from the text
output (tables, summaries, etc.). There are two ways to save graphs. You may copy and paste each graph
into a word document as you generate it. Or, you may save each graph individually: after you create a
graph, go to the File menu and click Save Graph; you will be prompted to specify a name and file
type for the graph. If you choose .gph you will be able to open the graph in Stata later on; if you
choose .ps you will be able to open it in another program (e.g., Ghostview or Acrobat with special
plug-in).

Analyzing Data
You can perform most statistical procedures in Stata using the pull-down menus or by typing commands
in the Command window. Some advanced procedures and options can only be executed by typing
commands in a Syntax window. The Stata Users Guide is a good source of information in these
situations. See Using the Command Syntax on page 8 for more information.

Using the Statistics Pull-down Menu


To perform a statistical procedure, use the Statistics pull-down menu to select the procedure you want
to perform. For example, to produce descriptive statistics on a variable in your data (for example, the
variables age and height), go into the Statistics menu, and select Summary Statistics from the
Summaries, Tables, and Tests submenu. A dialog box appears:

6 - Using Stata 8 for Windows


In the Summary Statistics dialog box, type the name of the variable or click on the variable in the
Variables window, then click OK. To view summary statistics for all variables, leave the variable box
empty and click OK. The summary statistics as well as the command you just executed appear in the
Results window:

To perform a linear regression, go into the Statistics menu, select Linear Regression and related, and
click on Linear Regression in the submenu. In the Linear Regression Main dialog box that appears,
designate a dependent variable by typing the name of the variable in the Dependent box and
independent variables by typing the names of the variable into the Independent(s) box. You can also
specify the confidence interval and request that Stata show normalized beta coefficients in your output.
Click on OK.

The results of the linear regression will appear in the results window. You can request additional
regression options by clicking on the By/If/In, Weights, Robust SE, Advanced tabs in the dialog box.

Creating Charts and Graphs


Use the Graphics pull-down menu to create graphs and charts. Stata can create a wide range of graphs
and charts and has lots of options for customizing them. For example, to create a scatterplot of the two

Using Stata 8 for Windows - 7


variables age and height, go into the Graphics menu and select Twoway Graph (Scatterplot, line,
etc...). In the dialog box that appears, enter the variable age into the X-axis box and height into the
Y-axis box. Then, click on OK. The graph will appear in the Viewer window:

You can add features such as a title to your charts and graphs, change the scale, range, or labels for your
graphs axes, and replace data points with meaningful symbols or markers. In the Twoway graph
dialog box, click on the appropriate tabs to customize your graph in these ways.

Using the Command Syntax


While you can perform most procedures in Stata using the pull-down menus, you will often find the
Command window to be a faster and easier way to work in Stata once you have learned some of the
basic commands. For example, to run summary statistics on the age variable in the Command window,
type:
summarize age
To get summary statistics on all variables in the dataset, simply type the command summarize without
specifying any variables. If you want to get summary statistics on many, but not all of the variables, it
may be quicker to click on the variables you want in the Variables window. The output will be the same
as in the menu-based Summary Statistics example shown above.
When you use the pull-down menus to perform procedures, the Results window will show the
appropriate command followed by the output. This is a good way to learn some of the commands when
you are first getting started with Stata. You can also find the syntax commands for statistical procedures
in the Stata manuals or in the Stata Help window. (See For More Information and Assistance on page
11.)
Creating Do-Files
You can also create command files (do-files) that let you submit several commands to Stata at once. To
enter the Do-File editor, click on the Do-File Editor button on the toolbar. The Do-File editor has the

8 - Using Stata 8 for Windows


standard features of a text editor (e.g., cut, copy, paste, undo, save, and print). Type each command on a
separate line. To run all of the commands in the Do-File, click the Do button .
As usual, the output from your procedure will appear in your Results window. Using the Do-File
window, you can keep a record of the analyses you have run. You can save your commands in a text
file, then open them again later to duplicate or expand your analysis. This option can be very useful for
long-term projects. To save the file, click on Save from the File menu, select a name for your file
(example), and select to save as type .do. You file will then have the name example.do.

Printing Files
You must purchase print quota to print at the Meyer or Tresidder clusters. More information about this
can be found at http://www.stanford.edu/services/cluster/printing.
To print numeric output such as frequencies or regression results, select Print Results from the File
menu. To print graphs, logs, or help information, make sure the Viewer window is in the foreground and
select Print Graph or Print Viewer from the File Menu. If you want to print only a portion of your
Viewer window, you can do so if your printer allows you to print selections. Highlight the desired
section by clicking in the area on the left-hand side of the window. Then, select Print from the File
menu. Make sure that the Selection button is clicked in the Print Range area of the Print dialog box,
then click OK.
You can also print Do-Files (command files). Choose Print from the File menu once the Do-File
window is in the foreground.

For More Information and Assistance

Stata Help
Stata has an extensive help system that provides information about using Stata and understanding the
results. To access the Stata Help system, go to the Help menu on the far right side of the screen and
select an option.
The Contents command lists a table of contents from which you can link to the topics listed, the Search
option allows you to search by keyword for help information, and the Stata command option allows
you to search for help information about a particular command.
Users can also access the Stata Home Page from the Help menu. This resource contains much up-to-
date information about Stata, including user support and frequently asked questions.

Stata Tutorials
For information on Stata tutorials and resources, see http://www.stata.com/links/resources1.html. The
short tutorial provided by Princeton University at the following address is particularly useful:
http://www.princeton.edu/~erp/stata/main.html
Stata also offers NetCourses. Information is listed at http://www.stata.com/netcourse.

Stata Documentation and Books


Please see the document Resources for Learning Stata on SSDS website.

Using Stata 8 for Windows - 9


You can read and photocopy Stata books and manuals in the Velma Denning Room (Green Library Bing
Wing, room 120F) or purchase them at the Stanford Bookstore. Some Stata manuals are also available to
be checked out from Green Library Reserves.

SSDS Software Services at Stanford


Software Services provides technical support for Stata users at Stanford. Users can ask questions or
make appointments with the consultants via our website. For more information or to contact us, see the
web at:
http://ssds.stanford.edu/

Note: This document is based on Stata 8 for Windows XP.


Copyright 2008, by The Board of Trustees of the Leland Stanford Junior University. Permission granted to copy for non-
commercial purposes, provided we receive acknowledgment and a copy of the document in which our material appears. No
right is granted to quote from or use any material in this document for purposes of promoting any product or service.
Social Science Data and Software
Document revised: 2/5/2008

10 - Using Stata 8 for Windows

You might also like