Stata For Windows
Stata For Windows
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
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
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.
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
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 .
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.
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.
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.
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.
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.
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.