SlideShare a Scribd company logo
1 of 148
Download to read offline
GETTING STARTED WITH STATA
FOR WINDOWS
R

RELEASE 13
®
A Stata Press Publication
StataCorp LP
College Station, Texas
®
Copyright c

 1985–2013 StataCorp LP
All rights reserved
Version 13
Published by Stata Press, 4905 Lakeway Drive, College Station, Texas 77845
Typeset in TEX
ISBN-10: 1-59718-114-5
ISBN-13: 978-1-59718-114-3
This manual is protected by copyright. All rights are reserved. No part of this manual may be reproduced, stored
in a retrieval system, or transcribed, in any form or by any means—electronic, mechanical, photocopy, recording, or
otherwise—without the prior written permission of StataCorp LP unless permitted subject to the terms and conditions
of a license granted to you by StataCorp LP to use the software and documentation. No license, express or implied,
by estoppel or otherwise, to any intellectual property rights is granted by this document.
StataCorp provides this manual “as is” without warranty of any kind, either expressed or implied, including, but
not limited to, the implied warranties of merchantability and fitness for a particular purpose. StataCorp may make
improvements and/or changes in the product(s) and the program(s) described in this manual at any time and without
notice.
The software described in this manual is furnished under a license agreement or nondisclosure agreement. The software
may be copied only in accordance with the terms of the agreement. It is against the law to copy the software onto
DVD, CD, disk, diskette, tape, or any other medium for any purpose other than backup or archival purposes.
The automobile dataset appearing on the accompanying media is Copyright c

 1979 by Consumers Union of U.S.,
Inc., Yonkers, NY 10703-1057 and is reproduced by permission from CONSUMER REPORTS, April 1979.
Icons other than the Stata icon are licensed from the Iconfactory, Inc. They remain property of the Iconfactory, Inc.,
and may not be reproduced or redistributed.
Stata, , Stata Press, Mata, , and NetCourse are registered trademarks of StataCorp LP.
Stata and Stata Press are registered trademarks with the World Intellectual Property Organization of the United Nations.
NetCourseNow is a trademark of StataCorp LP.
Other brand and product names are registered trademarks or trademarks of their respective companies.
For copyright information about the software, type help copyright within Stata.
The suggested citation for this software is
StataCorp. 2013. Stata: Release 13. Statistical Software. College Station, TX: StataCorp LP.
Contents
1 Introducing Stata—sample session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 The Stata user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3 Using the Viewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
4 Getting help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
5 Opening and saving Stata datasets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
6 Using the Data Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
7 Using the Variables Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
8 Importing data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
9 Labeling data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
10 Listing data and basic command syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
11 Creating new variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
12 Deleting variables and observations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
13 Using the Do-file Editor—automating Stata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
14 Graphing data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
15 Editing graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
16 Saving and printing results by using logs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
17 Setting font and window preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
18 Learning more about Stata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
19 Updating and extending Stata—Internet functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
A Troubleshooting Stata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
B Advanced Stata usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
C More on Stata for Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Subject index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
i
Cross-referencing the documentation
When reading this manual, you will find references to other Stata manuals. For example,
[U] 26 Overview of Stata estimation commands
[R] regress
[D] reshape
The first example is a reference to chapter 26, Overview of Stata estimation commands, in the User’s
Guide; the second is a reference to the regress entry in the Base Reference Manual; and the third
is a reference to the reshape entry in the Data Management Reference Manual.
All the manuals in the Stata Documentation have a shorthand notation:
[GSM] Getting Started with Stata for Mac
[GSU] Getting Started with Stata for Unix
[GSW] Getting Started with Stata for Windows
[U] Stata User’s Guide
[R] Stata Base Reference Manual
[D] Stata Data Management Reference Manual
[G] Stata Graphics Reference Manual
[XT] Stata Longitudinal-Data/Panel-Data Reference Manual
[ME] Stata Multilevel Mixed-Effects Reference Manual
[MI] Stata Multiple-Imputation Reference Manual
[MV] Stata Multivariate Statistics Reference Manual
[PSS] Stata Power and Sample-Size Reference Manual
[P] Stata Programming Reference Manual
[SEM] Stata Structural Equation Modeling Reference Manual
[SVY] Stata Survey Data Reference Manual
[ST] Stata Survival Analysis and Epidemiological Tables Reference Manual
[TS] Stata Time-Series Reference Manual
[TE] Stata Treatment-Effects Reference Manual:
Potential Outcomes/Counterfactual Outcomes
[I] Stata Glossary and Index
[M] Mata Reference Manual
iii
About this manual
This manual discusses Stata for Windows R

. Stata for Mac R

users should see Getting Started
with Stata for Mac; Stata for Unix R

users should see Getting Started with Stata for Unix. This
manual is intended both for people who are completely new to Stata and for experienced Stata users
new to Stata for Windows. Previous Stata users will also find it helpful as a tutorial on some new
features in Stata for Windows.
Following the numbered chapters are three appendixes with information specific to Stata for
Windows.
We provide several types of technical support to registered Stata users. [GSW] 4 Getting help
describes the resources available to help you learn about Stata’s commands and features. One of these
resources is the Stata website (http://www.stata.com), where you will find answers to frequently asked
questions (FAQs) as well as other useful information. If you still have questions after looking at the
Stata website and the other resources described in [GSW] 19 Updating and extending Stata—Internet
functionality, you can contact us as described in [U] 3.9 Technical support.
Using this manual
The new user will get the most out of this book by treating it as an exercise book, working through
each example at the computer. The material builds, so material from earlier chapters will often be
used in later chapters. Bear in mind that Stata is a rich and deep statistical package—just as statistics
itself is rich and deep. The time spent working the examples will be repaid with dividends when
doing true statistical analyses.
The experienced user may still have something to learn from this manual despite its name. We
suggest looking through the chapters to see if there is anything new or forgotten.
v
1 Introducing Stata—sample session
Introducing Stata
This chapter will run through a sample work session, introducing you to a few of the basic tasks
that can be done in Stata, such as opening a dataset, investigating the contents of the dataset, using
some descriptive statistics, making some graphs, and doing a simple regression analysis. As you
would expect, we will only brush the surface of many of these topics. This approach should give you
a sample of what Stata can do and how Stata works. There will be brief explanations along the way,
with references to chapters later in this book as well as to the system help and other Stata manuals.
We will run through the session by using both menus and dialogs and Stata’s commands so that you
can become familiar with them both.
Take a seat at your computer, put on some good music, and work along with the book.
Sample session
The dataset that we will use for this session is a set of data about vintage 1978 automobiles sold
in the United States.
To follow along by pointing and clicking, note that the menu items are given by Menu > Menu
Item > Submenu Item > etc. To follow along by using the Command window, type the commands
that follow a dot (.) in the boxed listings below into the small window labeled Command. When
there is something of note about the structure of a command, it will be pointed out as a “Syntax
note”.
Start by loading the auto dataset, which is included with Stata. To use the menus,
1. Select File > Example Datasets....
2. Click on Example datasets installed with Stata.
3. Click on use for auto.dta.
The result of this command is fourfold:
• The following output appears in the large Results window:
 
. sysuse auto.dta
(1978 Automobile Data)
 
The output consists of a command and its result. The command, sysuse auto.dta, is bold
and follows the period (.). The result, (1978 Automobile Data), is in the standard face
here and is a brief description of the dataset.
Note: If a command intrigues you, you can type help commandname in the Command window
to find help. If you want to explore at any time, Help  Search... can be informative.
• The same command, sysuse auto.dta, appears in the tall Review window to the left. The
Review window keeps track of all commands Stata has run, successful and unsuccessful. The
commands can then easily be rerun. See [GSW] 2 The Stata user interface for more information.
• A series of variables appears in the small Variables window to the upper right.
1
2 [ GSW ] 1 Introducing Stata—sample session
• Some information about make, the first variable in the dataset, appears in the small Properties
window to the lower right.
You could have opened the dataset by typing sysuse auto in the Command window and pressing
Enter. Try this now. sysuse is a command that loads (uses) example (system) datasets. As you will
see during this session, Stata commands are often simple enough that it is faster to use them directly.
This will be especially true once you become familiar with the commands you use the most in your
daily use of Stata.
Syntax note: In the above example, sysuse is the Stata command, whereas auto is the name of
a Stata data file.
Simple data management
We can get a quick glimpse at the data by browsing them in the Data Editor. This can be done
by clicking on the Data Editor (Browse) button, , or by selecting Data  Data Editor  Data
Editor (Browse) from the menus or by typing the command browse.
Syntax note: Here the command is browse and there are no other arguments.
When the Data Editor opens, you can see that Stata regards the data as one rectangular table. This
is true for all Stata datasets. The columns represent variables, whereas the rows represent observations.
The variables have somewhat descriptive names, whereas the observations are numbered.
The data are displayed in multiple colors—at first glance, it appears that the variables listed in black
are numeric, whereas those that are in colors are text. This is worth investigating. Click on a cell
under the make variable: the input box at the top displays the make of the car. Scroll to the right until
you see the foreign variable. Click on one of its cells. Although the cell may display “Domestic”,
the input box displays a 0. This shows that Stata can store categorical data as numbers but display
human-readable text. This is done by what Stata calls value labels. Finally, under the rep78 variable,
which looks to be numeric, there are some cells containing just a period (.). The periods correspond
to missing values.
[ GSW ] 1 Introducing Stata—sample session 3
Looking at the data in this fashion, though comfortable, lends little information about the dataset.
It would be useful for us to get more details about what the data are and how the data are stored.
Close the Data Editor by clicking on its close button.
We can see the structure of the dataset by describing its contents. This can be done either by
going to Data  Describe data  Describe data in memory or in a file in the menus and clicking
on OK or by typing describe in the Command window and pressing Enter. Regardless of which
method you choose, you will get the same result:
 
. describe
Contains data from C:Program FilesStata13/ado/base/a/auto.dta
obs: 74 1978 Automobile Data
vars: 12 13 Apr 2013 17:45
size: 3,182 (_dta has notes)
storage display value
variable name type format label variable label
make str18 %-18s Make and Model
price int %8.0gc Price
mpg int %8.0g Mileage (mpg)
rep78 int %8.0g Repair Record 1978
headroom float %6.1f Headroom (in.)
trunk int %8.0g Trunk space (cu. ft.)
weight int %8.0gc Weight (lbs.)
length int %8.0g Length (in.)
turn int %8.0g Turn Circle (ft.)
displacement int %8.0g Displacement (cu. in.)
gear_ratio float %6.2f Gear Ratio
foreign byte %8.0g origin Car type
Sorted by: foreign
 
If your listing stops short, and you see a blue more at the base of the Results window, pressing
the Spacebar or clicking on the blue more itself will allow the command to be completed.
At the top of the listing, some information is given about the dataset, such as where it is stored on
disk, how much memory it occupies, and when the data were last saved. The bold 1978 Automobile
Data is the short description that appeared when the dataset was opened and is referred to as a data
label by Stata. The phrase _dta has notes informs us that there are notes attached to the dataset.
We can see what notes there are by typing notes in the Command window:
 
. notes
_dta:
1. from Consumer Reports with permission
 
Here we see a short note about the source of the data.
Looking back at the listing from describe, we can see that Stata keeps track of more than just
the raw data. Each variable has the following:
• A variable name, which is what you call the variable when communicating with Stata. Variable
names are one type of Stata name. See [U] 11.3 Naming conventions.
• A storage type, which is the way Stata stores its data. For our purposes, it is enough to know
that types like, say, strnumber are string, or text, variables, whereas all others in this dataset
4 [ GSW ] 1 Introducing Stata—sample session
are numeric. While there are none in this dataset, Stata also allows arbitrarily long strings, or
strLs. strLs can even contain binary information. See [U] 12.4 Strings.
• A display format, which controls how Stata displays the data in tables. See [U] 12.5 Formats:
Controlling how data are displayed.
• A value label (possibly). This is the mechanism that allows Stata to store numerical data while
displaying text. See [GSW] 9 Labeling data and [U] 12.6.3 Value labels.
• A variable label, which is what you call the variable when communicating with other people.
Stata uses the variable label when making tables, as we will see.
A dataset is far more than simply the data it contains. It is also information that makes the data
usable by someone other than the original creator.
Although describing the data tells us something about the structure of the data, it says little about
the data themselves. The data can be summarized by clicking on Statistics  Summaries, tables,
and tests  Summary and descriptive statistics  Summary statistics and clicking on the OK
button. You could also type summarize in the Command window and press Enter. The result is a
table containing summary statistics about all the variables in the dataset:
 
. summarize
Variable Obs Mean Std. Dev. Min Max
make 0
price 74 6165.257 2949.496 3291 15906
mpg 74 21.2973 5.785503 12 41
rep78 69 3.405797 .9899323 1 5
headroom 74 2.993243 .8459948 1.5 5
trunk 74 13.75676 4.277404 5 23
weight 74 3019.459 777.1936 1760 4840
length 74 187.9324 22.26634 142 233
turn 74 39.64865 4.399354 31 51
displacement 74 197.2973 91.83722 79 425
gear_ratio 74 3.014865 .4562871 2.19 3.89
foreign 74 .2972973 .4601885 0 1
 
From this simple summary, we can learn a bit about the data. First of all, the prices are nothing like
today’s car prices—of course, these cars are now antiques. We can see that the gas mileages are not
particularly good. Automobile aficionados can get a feel for other esoteric characteristics.
There are two other important items here:
• The make variable is listed as having no observations. It really has no numerical observations
because it is a string (text) variable.
• The rep78 variable has five fewer observations than the other numerical variables. This implies
that rep78 has five missing values.
Although we could use the summarize and describe commands to get a bird’s eye view of the
dataset, Stata has a command that gives a good in-depth description of the structure, contents, and
values of the variables: the codebook command. Either type codebook in the Command window
and press Enter or navigate the menus to Data  Describe data  Describe data contents (codebook)
and click on OK. We get a large amount of output that is worth investigating. In fact, we get more
output than can fit on one screen, as can be seen by the blue more at the bottom of the Results
window. Press the Spacebar a few times to get all the output to scroll past. (For more about more ,
see More in [GSW] 10 Listing data and basic command syntax.) Look over the output to see that
[ GSW ] 1 Introducing Stata—sample session 5
much can be learned from this simple command. You can scroll back in the Results window to see
earlier results, if need be. We will focus on the output for make, rep78, and foreign.
To start our investigation, we would like to run the codebook command on just one variable,
say, make. We can do this, as usual, with menus or the command line. To get the codebook output
for make with the menus, start by navigating to Data  Describe data  Describe data contents
(codebook). When the dialog appears, there are multiple ways to tell Stata to consider only the make
variable:
• We could type make into the Variables field.
• The Variables field is a combobox control that accepts variable names. Clicking on the drop
triangle to the right of the Variables field displays a list of the variables from the current dataset.
Selecting a variable from the list will, in this case, enter the variable name into the edit field.
A much easier solution is to type codebook make in the Command window and then press Enter.
The result is informative:
 
. codebook make
make Make and Model
type: string (str18), but longest is str17
unique values: 74 missing : 0/74
examples: Cad. Deville
Dodge Magnum
Merc. XR-7
Pont. Catalina
warning: variable has embedded blanks
 
The first line of the output tells us the variable name (make) and the variable label (Make and Model).
The variable is stored as a string (which is another way of saying “text”) with a maximum length of
18 characters, though a size of only 17 characters would be enough. All the values are unique, so
if need be, make could be used as an identifier for the observations—something that is often useful
when putting together data from multiple sources or when trying to weed out errors from the dataset.
There are no missing values, but there are blanks within the makes. This latter fact could be useful
if we were expecting make to be a one-word string variable.
Syntax note: Telling the codebook command to run on the make variable is an example of using
a varlist in Stata’s syntax.
Looking at the foreign variable can teach us about value labels. We would like to look at the
codebook output for this variable, and on the basis of our latest experience, it would be easy to type
codebook foreign into the Command window (from here on, we will not explicitly say to press
the Enter key) to get the following output:
6 [ GSW ] 1 Introducing Stata—sample session
 
. codebook foreign
foreign Car type
type: numeric (byte)
label: origin
range: [0,1] units: 1
unique values: 2 missing .: 0/74
tabulation: Freq. Numeric Label
52 0 Domestic
22 1 Foreign
 
We can glean that foreign is an indicator variable because its only values are 0 and 1. The variable
has a value label that displays Domestic instead of 0 and Foreign instead of 1. There are two
advantages of storing the data in this form:
• Storing the variable as a byte takes less memory because each observation uses 1 byte instead of the
8 bytes needed to store “Domestic”. This is important in large datasets. See [U] 12.2.2 Numeric
storage types.
• As an indicator variable, it is easy to incorporate into statistical models. See [U] 25 Working
with categorical data and factor variables.
Finally, we can learn a little about a poorly labeled variable with missing values by looking at the
rep78 variable. Typing codebook rep78 into the Command window yields
 
. codebook rep78
rep78 Repair Record 1978
type: numeric (int)
range: [1,5] units: 1
unique values: 5 missing .: 5/74
tabulation: Freq. Value
2 1
8 2
30 3
18 4
11 5
5 .
 
rep78 appears to be a categorical variable, but because of lack of documentation, we do not know
what the numbers mean. (To see how we would label the values, see Changing data in [GSW] 6 Using
the Data Editor and see [GSW] 9 Labeling data.) This variable has five missing values, meaning
that there are five observations for which the repair record is not recorded. We could use the Data
Editor to investigate these five observations, but we will do this by using the Command window only
because doing so is much simpler. If you recall, the command brought up by clicking on the Data
Editor (Browse) button was browse. We would like to browse only those observations for which
rep78 is missing, so we could type
[ GSW ] 1 Introducing Stata—sample session 7
 
. browse if missing(rep78)
 
From this, we see that the . entries are indeed missing values. The . is the default numerical missing
value; Stata also allows .a, . . . , .z as user missing values, but we do not have any in our dataset.
See [U] 12.2.1 Missing values. Close the Data Editor after you are satisfied with this statement.
Syntax note: Using the if qualifier above is what allowed us to look at a subset of the observations.
Looking through the data lends no clues about why these particular data are missing. We decide
to check the source of the data to see if the missing values were originally missing or if they were
omitted in error. Listing the makes of the cars whose repair records are missing will be all we need
because we saw earlier that the values of make are unique. This can be done with the menus and a
dialog:
1. Select Data  Describe data  List data.
2. Click on the drop triangle to the right of the Variables field to show the variable names.
3. Click on make to enter it into the Variables field.
4. Click on the by/if/in tab in the dialog.
5. Type missing(rep78) into the If: (expression) box.
6. Click on Submit. Stata executes the proper command but the dialog remains open. Submit is
useful when experimenting, exploring, or building complex commands. We will primarily use
Submit in the examples. You may click on OK in its place if you like, and it will close the
dialog box.
The same ends could be achieved by typing list make if missing(rep78) in the Command
window. The latter is easier once you know that the command list is used for listing observations.
In any case, here is the output:
8 [ GSW ] 1 Introducing Stata—sample session
 
. list make if missing(rep78)
make
3. AMC Spirit
7. Buick Opel
45. Plym. Sapporo
51. Pont. Phoenix
64. Peugeot 604
 
We go to the original reference and find that the data were truly missing and cannot be resurrected.
See [GSW] 10 Listing data and basic command syntax for more information about all that can be
done with the list command.
Syntax note: This command uses two new concepts for Stata commands—the if qualifier and the
missing() function. The if qualifier restricts the observations on which the command runs to only
those observations for which the expression is true. See [U] 11.1.3 if exp. The missing() function
tests each observation to see if it contains a missing value. See [U] 13.3 Functions.
Now that we have a good idea about the underlying dataset, we can investigate the data themselves.
Descriptive statistics
We saw above that the summarize command gave brief summary statistics about all the variables.
Suppose now that we became interested in the prices while summarizing the data because they seemed
fantastically low (it was 1978, after all). To get an in-depth look at the price variable, we can use
the menus and a dialog:
1. Select Statistics  Summaries, tables, and tests  Summary and descriptive statistics 
Summary statistics.
2. Enter or select price in the Variables field.
3. Select Display additional statistics.
4. Click on Submit.
Syntax note: As can be seen from the Results window, typing summarize price, detail will get
the same result. The portion after the comma contains options for Stata commands; hence, detail
is an example of an option.
[ GSW ] 1 Introducing Stata—sample session 9
 
. summarize price, detail
Price
Percentiles Smallest
1% 3291 3291
5% 3748 3299
10% 3895 3667 Obs 74
25% 4195 3748 Sum of Wgt. 74
50% 5006.5 Mean 6165.257
Largest Std. Dev. 2949.496
75% 6342 13466
90% 11385 13594 Variance 8699526
95% 13466 14500 Skewness 1.653434
99% 15906 15906 Kurtosis 4.819188
 
From the output, we can see that the median price of the cars in the dataset is only $5,006.50! We can
also see that the four most expensive cars are all priced between $13,400 and $16,000. If we wished
to browse the most expensive cars (and gain some experience with features of the Data Editor), we
could start by clicking on the Data Editor (Browse) button, . Once the Data Editor is open, we
can click on the Filter Observations button, , to bring up the Filter Observations dialog. We can
look at the expensive cars by putting price  13000 in the Filter by expression field:
Pressing the Apply Filter button filters the data, and we can see that the expensive cars are two
Cadillacs and two Lincolns, which were not designed for gas mileage:
10 [ GSW ] 1 Introducing Stata—sample session
We now decide to turn our attention to foreign cars and repairs because as we glanced through the
data, it appeared that the foreign cars had better repair records. (We do not know exactly what the
categories 1, 2, 3, 4, and 5 mean, but we know the Chevy Monza was known for breaking down.)
Let’s start by looking at the proportion of foreign cars in the dataset along with the proportion of
cars with each type of repair record. We can do this with one-way tables. The table for foreign
cars can be done with menus and a dialog starting with Statistics  Summaries, tables, and tests
 Frequency tables  One-way table and then choosing the variable foreign in the Categorical
variable field. Clicking on Submit yields
 
. tabulate foreign
Car type Freq. Percent Cum.
Domestic 52 70.27 70.27
Foreign 22 29.73 100.00
Total 74 100.00
 
We see that roughly 70% of the cars in the dataset are domestic, whereas 30% are foreign. The value
labels are used to make the table so that the output is nicely readable.
Syntax note: We also see that this one-way table could be made by using the tabulate command
together with one variable, foreign. Making a one-way table for the repair records is simple—it
will be simpler if done with the Command window. Typing tabulate rep78 yields
 
. tabulate rep78
Repair
Record 1978 Freq. Percent Cum.
1 2 2.90 2.90
2 8 11.59 14.49
3 30 43.48 57.97
4 18 26.09 84.06
5 11 15.94 100.00
Total 69 100.00
 
We can see that most cars have repair records of 3 and above, though the lack of value labels makes us
unsure what a “3” means. Take our word for it that 1 means a poor repair record and 5 means a good
[ GSW ] 1 Introducing Stata—sample session 11
repair record. The five missing values are indirectly evident because the total number of observations
listed is 69 rather than 74.
These two one-way tables do not help us compare the repair records of foreign and domestic cars.
A two-way table would help greatly, which we can get by using the menus and a dialog:
1. Select Statistics  Summaries, tables, and tests  Frequency tables  Two-way table with
measures of association.
2. Choose rep78 as the Row variable.
3. Choose foreign as the Column variable.
4. It would be nice to have the percentages within the foreign variable, so check the Within-row
relative frequencies checkbox.
5. Click on Submit.
Here is the resulting output:
 
. tabulate rep78 foreign, row
Key
frequency
row percentage
Repair
Record Car type
1978 Domestic Foreign Total
1 2 0 2
100.00 0.00 100.00
2 8 0 8
100.00 0.00 100.00
3 27 3 30
90.00 10.00 100.00
4 9 9 18
50.00 50.00 100.00
5 2 9 11
18.18 81.82 100.00
Total 48 21 69
69.57 30.43 100.00
 
The output indicates that foreign cars are generally much better than domestic cars when it comes
to repairs. If you like, you could repeat the previous dialog and try some of the hypothesis tests
available from the dialog. We will abstain.
Syntax note: We see that typing the command tabulate rep78 foreign, row would have given
us the same table. Thus using tabulate with two variables yields a two-way table. It makes sense
that row is an option—we went out of our way to check it in the dialog. Using the row option allows
us to change the behavior of the tabulate command from its default.
Continuing our exploratory tour of the data, we would like to compare gas mileages between
foreign and domestic cars, starting by looking at the summary statistics for each group by itself. A
direct way to do this would be to use if qualifiers to summarize mpg for each of the two values of
foreign separately:
12 [ GSW ] 1 Introducing Stata—sample session
 
. summarize mpg if foreign==0
Variable Obs Mean Std. Dev. Min Max
mpg 52 19.82692 4.743297 12 34
. summarize mpg if foreign==1
Variable Obs Mean Std. Dev. Min Max
mpg 22 24.77273 6.611187 14 41
 
It appears that foreign cars get somewhat better gas mileage—we will test this soon.
Syntax note: We needed to use a double equal sign (==) for testing equality. The double equal
sign could be familiar to you if you have programmed before. If it is unfamiliar, be aware that it is a
common source of errors when initially using Stata. Thinking of equality as “exactly equal” can cut
down on typing errors.
There are two other methods that we could have used to produce these summary statistics. These
methods are worth knowing because they are less error-prone. The first method duplicates the concept
of what we just did by exploiting Stata’s ability to run a command on each of a series of nonoverlapping
subsets of the dataset. To use the menus and a dialog, do the following:
1. Select Statistics  Summaries, tables, and tests  Summary and descriptive statistics 
Summary statistics and click on the Reset button, .
2. Select mpg in the Variables field.
3. Select the Standard display option (if it is not already selected).
4. Click on the by/if/in tab.
5. Check the Repeat command by groups checkbox.
6. Select or type foreign in the Variables that define groups field.
7. Submit the command.
You can see that the results match those from above. They have a better appearance than the two
commands above because the value labels Domestic and Foreign are used rather than the numerical
values. The method is more appealing because the results were produced without needing to know
the possible values of the grouping variable ahead of time.
 
. by foreign, sort : summarize mpg
- foreign = Domestic
Variable Obs Mean Std. Dev. Min Max
mpg 52 19.82692 4.743297 12 34
- foreign = Foreign
Variable Obs Mean Std. Dev. Min Max
mpg 22 24.77273 6.611187 14 41
 
Syntax note: There is something different about the equivalent command that appears above: it contains
a prefix command called a by prefix. The by prefix has its own option, namely, sort, to ensure
that like members are adjacent to each other before being summarized. The by prefix command is
important for understanding data manipulation and working with subpopulations within Stata. Make
good note of this example, and consult [U] 11.1.2 by varlist: and [U] 27.2 The by construct for more
[ GSW ] 1 Introducing Stata—sample session 13
information. Stata has other prefix commands for specialized treatment of commands, as explained
in [U] 11.1.10 Prefix commands.
The third method for tabulating the differences in gas mileage across the cars’ origins involves
thinking about the structure of desired output. We need a one-way table of automobile types (foreign
versus domestic) within which we see information about gas mileages. Looking through the menus
yields the menu item Statistics  Summaries, tables, and tests  Other tables  Table of means,
std. dev., and frequencies. Selecting this, entering foreign for Variable 1 and mpg for the Summarize
variable, and submitting the command yields a nice table:
 
. tabulate foreign, summarize(mpg)
Summary of Mileage (mpg)
Car type Mean Std. Dev. Freq.
Domestic 19.826923 4.7432972 52
Foreign 24.772727 6.6111869 22
Total 21.297297 5.7855032 74
 
The equivalent command is evidently tabulate foreign, summarize(mpg).
Syntax note: This is a one-way table, so tabulate uses one variable. The variable being summarized
is passed to the tabulate command with an option. Though we will not do it here, the summarize()
option can also be used with two-way tables.
A simple hypothesis test
We would like to run a hypothesis test for the difference in the mean gas mileages. Under the menus,
Statistics  Summaries, tables, and tests  Classical tests of hypotheses  t test (mean-comparison
test) leads to the proper dialog. Select the Two-sample using groups radio button, enter mpg for the
Variable name and foreign for the Group variable name, and Submit the dialog. The results are
 
. ttest mpg, by(foreign)
Two-sample t test with equal variances
Group Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
Domestic 52 19.82692 .657777 4.743297 18.50638 21.14747
Foreign 22 24.77273 1.40951 6.611187 21.84149 27.70396
combined 74 21.2973 .6725511 5.785503 19.9569 22.63769
diff -4.945804 1.362162 -7.661225 -2.230384
diff = mean(Domestic) - mean(Foreign) t = -3.6308
Ho: diff = 0 degrees of freedom = 72
Ha: diff  0 Ha: diff != 0 Ha: diff  0
Pr(T  t) = 0.0003 Pr(|T|  |t|) = 0.0005 Pr(T  t) = 0.9997
 
From this, we could conclude that the mean gas mileage for foreign cars is different from that of
domestic cars (though we really ought to have wanted to test this before snooping through the data).
We can also conclude that the command, ttest mpg, by(foreign), is easy enough to remember.
Feel free to experiment with unequal variances, various approximations to the number of degrees of
freedom, and the like.
14 [ GSW ] 1 Introducing Stata—sample session
Syntax note: The by() option used here is not the same as the by prefix command used earlier.
Although it has a similar conceptual meaning, its usage is different because it is a particular option
for the ttest command.
Descriptive statistics—correlation matrices
We now change our focus from exploring categorical relationships to exploring numerical relation-
ships: we would like to know if there is a correlation between miles per gallon and weight. We select
Statistics  Summaries, tables, and tests  Summary and descriptive statistics  Correlations
and covariances in the menus. Entering mpg and weight, either by clicking or by typing, and then
submitting the command yields
 
. correlate mpg weight
(obs=74)
mpg weight
mpg 1.0000
weight -0.8072 1.0000
 
The equivalent command for this is natural: correlate mpg weight. There is a negative correlation,
which is not surprising because heavier cars should be harder to push about.
We could see how the correlation compares for foreign and domestic cars by using our knowledge
of the by prefix. We can reuse the correlate dialog or use the menus as before if the dialog is closed.
Click on the by/if/in tab, check the Repeat command by groups checkbox, and enter the foreign
variable to define the groups. As done on page 12, a simple by foreign, sort: prefix in front of
our previous command would work, too:
 
. by foreign, sort: correlate mpg weight
- foreign = Domestic
(obs=52)
mpg weight
mpg 1.0000
weight -0.8759 1.0000
- foreign = Foreign
(obs=22)
mpg weight
mpg 1.0000
weight -0.6829 1.0000
 
We see from this that the correlation is not as strong among the foreign cars.
Syntax note: Although we used the correlate command to look at the correlation of two variables,
Stata can make correlation matrices for an arbitrary number of variables:
[ GSW ] 1 Introducing Stata—sample session 15
 
. correlate mpg weight length turn displacement
(obs=74)
mpg weight length turn displa~t
mpg 1.0000
weight -0.8072 1.0000
length -0.7958 0.9460 1.0000
turn -0.7192 0.8574 0.8643 1.0000
displacement -0.7056 0.8949 0.8351 0.7768 1.0000
 
This can be useful, for example, when investigating collinearity among predictor variables.
Graphing data
We have found several things in our investigations so far: We know that the average MPG of
domestic and foreign cars differs. We have learned that domestic and foreign cars differ in other
ways as well, such as in frequency-of-repair record. We found a negative correlation between MPG
and weight—as we would expect—but the correlation appears stronger for domestic cars.
We would now like to examine, with an eye toward modeling, the relationship between MPG and
weight, starting with a graph. We can start with a scatterplot of mpg against weight. The command
for this is simple: scatter mpg weight. Using the menus requires a few steps because the graphs
in Stata may be customized heavily.
1. Select Graphics  Twoway graph (scatter, line, etc.).
2. Click on the Create... button.
3. Select the Basic plots radio button (if it is not already selected).
4. Select Scatter as the basic plot type (if it is not already selected).
5. Select mpg as the Y variable and weight as the X variable.
6. Click on the Submit button.
The Results window shows the command that was issued from the menu:
 
. twoway (scatter mpg weight)
 
The command issued when the dialog was submitted is a bit more complex than the command
suggested above. There is good reason for this: the more complex structure allows combining and
overlaying graphs, as we will soon see. In any case, the graph that appears is
16 [ GSW ] 1 Introducing Stata—sample session
10
20
30
40
Mileage
(mpg)
2,000 3,000 4,000 5,000
Weight (lbs.)
We see the negative correlation in the graph, though the relationship appears to be nonlinear.
Note: When you draw a graph, the Graph window appears, probably covering up your Results
window. Click on the main Stata window to get the Results window back on top. Want to see the
graph again? Click on the Graph button, . See The Graph button in [GSW] 14 Graphing data
for more information about the Graph button.
We would now like to see how the different correlations for foreign and domestic cars are manifested
in scatterplots. It would be nice to see a scatterplot for each type of car, along with a scatterplot for
all the data.
Syntax note: Because we are looking at subgroups, this looks as if it is a job for the by prefix.
Let’s see if this is what we really should use.
Start as before:
1. Select Graphics  Twoway graph (scatter, line, etc.) from the menus.
2. If the Plot 1 dialog is still visible, click on the Accept button and skip to step 4.
3. Go through the process on the previous page to create the graph.
4. Click on the By tab of the twoway - Twoway graphs dialog.
5. Check the Draw subgraphs for unique values of variables checkbox.
6. Enter foreign in the Variables field.
7. Check the Add a graph with totals checkbox.
8. Click on the Submit button.
[ GSW ] 1 Introducing Stata—sample session 17
The command and the associated graph are
 
. twoway (scatter mpg weight), by(foreign, total)
 
10
20
30
40
10
20
30
40
2,000 3,000 4,000 5,000
2,000 3,000 4,000 5,000
Domestic Foreign
Total
Mileage
(mpg)
Weight (lbs.)
Graphs by Car type
The graphs show that the relationship is nonlinear for both types of cars.
Syntax note: To make the graphs for the combined subgroups, we ended up using a by() option,
not a by prefix. If we had used a by prefix, separate graphs would have been generated instead of
the combined graph created by the by() option.
Model fitting: Linear regression
After looking at the graphs, we would like to fit a regression model that predicts MPG from the
weight and type of the car. From the graphs, we see that the relationship is nonlinear, so we will
try modeling MPG as a quadratic in weight. Also from the graphs, we judge the relationship to be
different for domestic and foreign cars. We will include an indicator (dummy) variable for foreign
and evaluate afterward whether this adequately describes the difference. Thus we will fit the model
mpg = β0 + β1 weight + β2 weight2
+ β3 foreign + 
foreign is already an indicator (0/1) variable, but we need to create the weight-squared variable.
This can be done with the menus, but here using the command line is simpler. Type
 
. generate wtsq = weight^2
18 [ GSW ] 1 Introducing Stata—sample session
Now that we have all the variables we need, we can run a linear regression. We will use the
menus and see that the command is also simple. To use the menus, select Statistics  Linear models
and related  Linear regression. In the resulting dialog, choose mpg as the Dependent variable
and weight, wtsq, and foreign as the Independent variables. Submit the command. Here is the
equivalent simple regress command and the resulting analysis-of-variance table.
 
. regress mpg weight wtsq foreign
Source SS df MS Number of obs = 74
F( 3, 70) = 52.25
Model 1689.15372 3 563.05124 Prob  F = 0.0000
Residual 754.30574 70 10.7757963 R-squared = 0.6913
Adj R-squared = 0.6781
Total 2443.45946 73 33.4720474 Root MSE = 3.2827
mpg Coef. Std. Err. t P|t| [95% Conf. Interval]
weight -.0165729 .0039692 -4.18 0.000 -.0244892 -.0086567
wtsq 1.59e-06 6.25e-07 2.55 0.013 3.45e-07 2.84e-06
foreign -2.2035 1.059246 -2.08 0.041 -4.3161 -.0909002
_cons 56.53884 6.197383 9.12 0.000 44.17855 68.89913
 
The results look encouraging, so we will plot the predicted values on top of the scatterplots for each
of the types of cars. To do this, we need the predicted, or fitted, values. This can be done with
the menus, but doing it in the Command window is simple enough. We will create a new variable,
mpghat to hold the predicted MPG for each car. Type
 
. predict mpghat
(option xb assumed; fitted values)
 
The output from this command is simply a notification. Go over to the Variables window and scroll
to the bottom to confirm that there is now an mpghat variable. If you were to try this command
when mpghat already existed, Stata would refuse to overwrite your data:
 
. predict mpghat
mpghat already defined
r(110);
 
The predict command, when used after a regression, is called a postestimation command. As
specified, it creates a new variable called mpghat equal to
−0.0165729 weight + 1.59 × 10−6
wtsq − 2.2035 foreign + 56.53884
For careful model fitting, there are several features available to you after estimation—one is
calculating predicted values. Be sure to read [U] 20 Estimation and postestimation commands.
We can now graph the data and the predicted curve to evaluate separately the fit on the foreign
and domestic data to determine if our shift parameter is adequate. We can draw both graphs together.
Using the menus and a dialog, do the following:
1. Select Graphics  Twoway graph (scatter, line, etc.) from the menus.
2. If there are any plots listed, click on the Reset button, , to clear the dialog box.
[ GSW ] 1 Introducing Stata—sample session 19
3. Create the graph for mpg versus weight:
a. Click on the Create... button.
b. Be sure that Basic plots and Scatter are selected.
c. Select mpg as the Y variable and weight as the X variable.
d. Click on Accept.
4. Create the graph showing mpghat versus weight
a. Click on the Create... button.
b. Select Basic plots and Line.
c. Select mpghat as the Y variable and weight as the X variable.
d. Check the Sort on x variable box. Doing so ensures that the lines connect from smallest
to largest weight values, instead of the order in which the data happen to be.
e. Click on Accept.
5. Show two plots, one each for domestic and foreign cars, on the same graph:
a. Click on the By tab.
b. Check the Draw subgraphs for unique values of variables checkbox.
c. Enter foreign in the Variables field.
6. Click on the Submit button.
Here are the resulting command and graph:
 
. twoway (scatter mpg weight) (line mpghat weight, sort), by(foreign)
 
10
20
30
40
2,000 3,000 4,000 5,000 2,000 3,000 4,000 5,000
Domestic Foreign
Mileage (mpg) Fitted values
Weight (lbs.)
Graphs by Car type
20 [ GSW ] 1 Introducing Stata—sample session
Here we can see the reason for enclosing the separate scatter and line commands in parentheses:
they can thereby be overlaid by submitting them together. The fit of the plots looks good and is cause
for initial excitement. So much excitement, in fact, that we decide to print the graph and show it to
an engineering friend. We print the graph, being careful to print the graph (and not all our results),
by choosing File  Print... from the Graph window menu bar.
When we show our graph to our engineering friend, she is concerned. “No,” she says. “It should
take twice as much energy to move 2,000 pounds 1 mile compared with moving 1,000 pounds the
same distance: therefore, it should consume twice as much gasoline. Miles per gallon is not quadratic
in weight; gallons per mile is a linear function of weight. Don’t you remember any physics?”
We try out what she says. We need to generate an energy-per-distance variable and make a
scatterplot. Here are the commands that we would need—note their similarity to commands issued
earlier in the session. There is one new command, the label variable command, which allows us
to give the gpm100m variable a variable label so that the graph is labeled nicely.
 
. generate gp100m = 100/mpg
. label variable gp100m Gallons per 100 miles
. twoway (scatter gp100m weight), by(foreign, total)
 
2
4
6
8
2
4
6
8
2,000 3,000 4,000 5,000
2,000 3,000 4,000 5,000
Domestic Foreign
Total
Gallons
per
100
miles
Weight (lbs.)
Graphs by Car type
[ GSW ] 1 Introducing Stata—sample session 21
Sadly satisfied that the engineer is indeed correct, we rerun the regression:
 
. regress gp100m weight foreign
Source SS df MS Number of obs = 74
F( 2, 71) = 113.97
Model 91.1761694 2 45.5880847 Prob  F = 0.0000
Residual 28.4000913 71 .400001287 R-squared = 0.7625
Adj R-squared = 0.7558
Total 119.576261 73 1.63803097 Root MSE = .63246
gp100m Coef. Std. Err. t P|t| [95% Conf. Interval]
weight .0016254 .0001183 13.74 0.000 .0013896 .0018612
foreign .6220535 .1997381 3.11 0.003 .2237871 1.02032
_cons -.0734839 .4019932 -0.18 0.855 -.8750354 .7280677
 
We find that foreign cars had better gas mileage than domestic cars in 1978 because they were so
light. According to our model, a foreign car with the same weight as a domestic car would use an
additional 5/8 gallon (or 5 pints) of gasoline per 100 miles driven. With this conclusion, we are
satisfied with our analysis.
Commands versus menus
In this chapter, you have seen that Stata can operate either with menu choices and dialogs or with
the Command window. As you become more familiar with Stata, you will find that the Command
window is typically much faster for oft-used commands, whereas the menus and dialogs are faster
when building up complex commands, such as those that create graphs.
One of Stata’s great strengths is the consistency of its command syntax. Most of Stata’s commands
share the following syntax, where square brackets mean that something is optional, and a varlist is a
list of variables.

prefix:

command

varlist
 
if
 
in
 
weight
 
, options

Some general rules:
• Most commands accept prefix commands that modify their behavior; see [U] 11.1.10 Prefix
commands for details. One of the common prefix commands is by.
• If an optional varlist is not specified, all the variables are used.
• if and in restrict the observations on which the command is run.
• options modify what the command does.
• Each command’s syntax is found in the system help and the reference manuals.
• Stata’s command syntax includes more than we have shown you here, but this introduction
should get you started. For more information, see [U] 11 Language syntax and help language.
We saw examples using all the pieces of this except for the in qualifier and the weight clause. The
syntax for all commands can be found in the system help along with examples—see [GSW] 4 Getting
help for more information. The consistent syntax makes it straightforward to learn new commands
and to read others’ commands when examining an analysis.
Here is an example of reading the syntax diagram that uses the summarize command from earlier
in this chapter. The syntax diagram for summarize is typical:
summarize

varlist
 
if
 
in
 
weight
 
, options
22 [ GSW ] 1 Introducing Stata—sample session
This means that
command by itself is valid: summarize
command followed by a varlist
(variable list) is valid: summarize mpg
summarize mpg weight
command with if (with or without
a varlist) is valid: summarize if mpg20
summarize mpg weight if mpg20
and so on.
You can learn about summarize in [R] summarize, or select Help  Stata Command... and enter
summarize, or type help summarize in the Command window.
Keeping track of your work
It would have been useful if we had made a log of what we did so that we could conveniently
look back at interesting results or track any changes that were made. You will learn to do this in
[GSW] 16 Saving and printing results by using logs. Your logs will contain commands and their
output—another reason to learn command syntax is so that you can remember what you have done.
To make a log file that keeps track of everything appearing in the Results window, click on the
Log button, which looks like a lab notebook, . Choose a place to store your log file, and give
it a name, just as you would for any other document. The log file will save everything that appears
in the Results window from the time you start a log file to the time you close it.
Conclusion
This chapter introduced you to Stata’s capabilities. You should now read and work through the
rest of this manual. Once you are done here, you can read the User’s Guide.
2 The Stata user interface
The windows
This chapter introduces the core of Stata’s interface: its main windows, its toolbar, its menus, and
its dialogs.
The five main windows are the Review, Results, Command, Variables, and Properties windows.
Except for the Results window, each window has its name in its title bar. These five windows are
typically in use the whole time Stata is open. There are other, more specialized windows such as the
Viewer, Data Editor, Variables Manager, Do-file Editor, Graph, and Graph Editor windows—these
are discussed later in this manual.
To open any window or to reveal a window hidden by other windows, select the window from
the Window menu, or select the proper item from the toolbar. You can also use Ctrl+Tab to cycle
through all open windows inside the main Stata window or Alt+Tab to cycle through all open windows
(Stata and other) if you want to change windows from the keyboard. Many of Stata’s windows have
functionality that can be accessed by clicking on the right mouse button (right-clicking) within the
window. Right-clicking displays a contextual menu that, depending on the window, allows you to
copy text, set the preferences for the window, or print the contents of the window. When you copy
text or print, we recommend that you always right-click on the window rather than use the menu bar
or toolbar so that you can be sure of where and what you are copying or printing.
23
24 [ GSW ] 2 The Stata user interface
The toolbar
This is the toolbar:
The toolbar contains buttons that provide quick access to Stata’s more commonly used features.
If you forget what a button does, hold the mouse pointer over the button for a moment, and a tooltip
will appear with a description of that button.
Buttons that include both an icon and an arrow display a menu if you click on the arrow. Here is
an overview of the toolbar buttons and their functions:
Open opens a Stata dataset. Click on the button to open a dataset with the Open
dialog.
Save saves the Stata dataset currently in memory to disk.
Print displays a list of windows. Select a window name to print its contents.
Log begins a new log or closes, suspends, or resumes the current log. See
[GSW] 16 Saving and printing results by using logs for an explanation of log
files.
Viewer opens the Viewer or brings a Viewer to the front of all other windows. Click
on the button to open a new Viewer. Click on the arrow to select a Viewer to bring
to the front. See [GSW] 3 Using the Viewer for more information.
Graph brings a Graph window to the front of all other windows. Click on the button
to bring the Graph window to the front. Click on the arrow to select a Graph window
to bring to the front. See The Graph button in [GSW] 14 Graphing data for more
information.
Do-file Editor opens the Do-file Editor or brings a Do-file Editor to the front of
all other windows. Click on the button to open a new Do-file Editor. Click on the
arrow to select a Do-file Editor to bring to the front. See [GSW] 13 Using the Do-file
Editor—automating Stata for more information.
Data Editor (Edit) opens the Data Editor or brings the Data Editor to the front of
the other Stata windows. See [GSW] 6 Using the Data Editor for more information.
Data Editor (Browse) opens the Data Editor in browse mode. See Browse mode in
[GSW] 6 Using the Data Editor for more information.
Variables Manager opens the Variables Manager. See [GSW] 7 Using the Variables
Manager for more information.
Clear more Condition tells Stata to continue when it has paused in the middle
of long output. See [GSW] 10 Listing data and basic command syntax for more
information.
Break stops the current task in Stata. See [GSW] 10 Listing data and basic command
syntax for more information.
[ GSW ] 2 The Stata user interface 25
The Command window
Commands are submitted to Stata from the Command window. The Command window supports
basic text editing, copying and pasting, a command history, function-key mapping, and variable-name
completion.
From the Command window, pressing
Page Up steps backward through the command history.
Page Down steps forward through the command history.
Tab auto-completes a partially typed variable name, when possible.
See [U] 10 Keyboard use for more information about keyboard shortcuts for the Command window.
The command history allows you to recall a previously submitted command, edit it if you wish,
and then resubmit it. Commands submitted by Stata’s dialogs are also included in the command
history, so you can recall and submit a command without having to open the dialog again.
The Results window
The Results window contains all the commands and their textual results you have entered during
the Stata session. While you can scroll through the Results window to look at work you have done,
it is much simpler to search within the Results window by using the find bar. By default, the find
bar is hidden. You can expose it by selecting Edit  Find.
You can clear out the Results window at any time by right-clicking in the Results window and
selecting Clear Results from the contextual menu. This action is not undoable.
The Review window
The Review window shows the history of commands that have been entered. It displays successful
commands in black and unsuccessful commands, along with their error codes, in red.
The toolbar has two tools for manipulating the contents of the Review window. Clicking on the
Filter button, , in the Review window titlebar toggles the visibility of these tools. Text entered in
the Filter commands here field will filter the commands appearing in the Review window. By default,
the filter will ignore case and find any commands containing any of the words in the filter. Clicking
on the wrench on the left will allow you to change this behavior. Clicking on the exclamation mark
button toggles the hiding of commands that ran with an error.
No commands are deleted by using these tools—all that is affected is their visibility.
To enter a command from the Review window, you can
• Click once on a past command to copy it to the Command window, replacing the contents of
the Command window.
• Double-click on a past command to resubmit it. Executing the command adds the command to
the bottom of the Review window.
Right-clicking on the Review window displays a menu from which you can select various actions:
• Cut removes the selected commands from the Review window and places them on the Clipboard.
• Copy copies the selected commands to the Clipboard.
• Delete removes the selected commands from the Review window.
• Select All selects all the commands in the Review window, including those before and after
the commands currently displayed.
26 [ GSW ] 2 The Stata user interface
• Clear All clears out all the commands from the Review window, including those before and
after the commands currently displayed.
• Do Selected submits all the selected commands and adds them to the bottom of the command
history. Stata will attempt to run all the selected commands, even those containing errors, and
will not stop even if a command causes an error.
• Send to Do-file Editor places all the selected commands into a new Do-file Editor window.
• Save All... brings up a Save Review Contents dialog, which allows you to save all the commands
in the Review window, including those before and after the commands currently displayed, in
a do-file. (See [GSW] 13 Using the Do-file Editor—automating Stata for more information
on do-files.)
• Save Selected... brings up a Save Review Contents dialog, which allows you to save the selected
commands in the Review window in a do-file.
• Font... brings up a Font dialog, allowing you to change the font used to display the Review
window contents.
The Variables window
The Variables window shows the list of variables in the dataset, along with selected properties of
the variables. By default, it shows all the variables and their variable labels. You can change what
properties get displayed by right-clicking on the header of any column of the Variables window.
Click once on a variable in the Variables window to select it. Multiple variables can be selected
in the usual fashion, either by Ctrl-clicking on nonadjacent variables or by clicking on a variable and
shift-clicking on a second variable to select all intervening variables.
Double-clicking on a variable in the Variables window puts the selected variable at the insertion
point in the Command window.
The leftmost column of the Variables window is called the one-click paste column. You can also
send variables to the Command window by hovering the mouse over the one-click paste column of
the Variables window and clicking on the arrow that appears. The one-click paste column can be
shown or hidden in the same fashion as the other columns in the Variables window.
The Variables window supports filtering and reordering of variables. Clicking on the Filter button,
, in the Variables window titlebar toggles the visibility of the filter. Text entered in the Filter
variables here field will filter the variables appearing in the Variables window. The filter is applied to
all visible columns and shows all variables that match the criteria in at least one column. By default,
the filter will ignore case and show any variables for which at least one column contains any of the
words in the filter. Clicking on the wrench on the left will allow you to change this behavior as well
as add or remove additional columns containing information about the variables.
You can reorder the variables in the Variables window by clicking on any column header. The
first click sorts in ascending order, the second click sorts in descending order, and the third click
puts the variables back in dataset order. Thus clicking on the Variable column header will make the
Variables window display the variables in alphabetical order. Sorting in the Variables window is live,
so if you change a property of a variable when the Variables window is sorted by that property, it will
automatically move the variable to its proper location. Reordering the display order of the variables
in the Variables window does not affect the order of the variables in the dataset itself.
[ GSW ] 2 The Stata user interface 27
Right-clicking on a variable in the Variables window displays a menu from which you can select
• Keep Only Selected Variables to keep just the selected variables in the dataset in memory.
You will be asked for confirmation. This affects only the dataset in memory, not the dataset as
saved on your disk. See [GSW] 12 Deleting variables and observations for more information.
• Drop Selected Variables to drop, or eliminate, the selected variables from the dataset in memory.
You will be asked for confirmation. Just as above, this affects only the dataset in memory, not
the dataset as saved on your disk. See [GSW] 12 Deleting variables and observations for more
information.
• Copy Varlist to copy the selected variable names to the clipboard.
• Select All to select all variables in the dataset that satisfy the filter conditions. If no filter has
been specified, all variables will be selected.
• Send Varlist to Command Window to send all selected variables to the Command window.
• Font... to bring up a Font dialog, allowing you to change the font used to display the Variables
window contents.
Items from the contextual menu issue standard Stata commands, so working by right-clicking is just
like working directly in the Command window.
If you would like to hide the Variables window, click on its close button.
To reveal a hidden Variables window, select Window  Variables.
The Properties window
The Properties window displays variable and dataset properties. If a single variable is selected
in the Variables window, its properties are displayed. If there are multiple variables selected in the
Variables window, the Properties window will display properties that are common across all selected
variables.
Clicking the lock icon in the Properties window titlebar toggles the ability to alter properties of
the selected variables. By default, changes are not allowed. Once the properties are unlocked, you
can make any changes to variable or dataset properties you like. Each change you make will create
a command that appears in the Results and Command windows, as well as in any command log, so
the changes are reproducible. Using the Properties window is one of the simplest ways of managing
notes, changing variable and value labels, and changing display formats. See [D] notes, [D] label,
and [D] format.
Clicking the arrow buttons next to the lock icon will select the previous or next variable shown
in the Variables window, and that selection will be reflected in the Properties window.
If you would like to hide the Properties window, click on its close box. If you would like to
reveal a hidden Properties window, select Window  Properties.
You should also investigate the Variables Manager, explained in [GSW] 7 Using the Variables
Manager, because it extends these capabilities and provides a good interface for managing variables.
Menus and dialogs
There are two ways by which you can tell Stata what you would like it to do: you can use menus
and dialogs, or you can use the Command window. When you worked through the sample session in
[GSW] 1 Introducing Stata—sample session, you saw that both ways have strengths. We will discuss
the menus and dialogs here.
28 [ GSW ] 2 The Stata user interface
Stata’s Data, Graphics, and Statistics menus provide point-and-click access to almost every
command in Stata. As you will learn, Stata is fully programmable, and Stata users can even create
their own dialogs and menus. The User menu provides a place for programmers to add their own
menu items. Initially, it contains only some empty submenus. As an example, suppose you wish
to perform a Poisson regression. You could type Stata’s poisson command, or you could select
Statistics  Count outcomes  Poisson regression, which would display this dialog:
This dialog provides access to all the functionality of Stata’s poisson command. Because the
dependent and independent variables must be numeric, you will find that the combobox will display
only numeric variables for choosing. The poisson command has many options that can be accessed
by clicking on the multiple tabs across the top of the dialog. The first time you use the dialog for a
command, it is a good idea to look at the contents of each tab so that you will know all the dialog’s
capabilities.
The dialogs for many commands have the by/if/in and Weights tabs. These provide access to
Stata’s commands and qualifiers for controlling the estimation sample and dealing with weighted data.
See [U] 11 Language syntax for more information on these features of Stata’s language.
The dialogs for most estimation commands have the Maximization tab for setting the maximization
options (see [R] maximize). For example, you can specify the maximum number of iterations for the
optimizer.
[ GSW ] 2 The Stata user interface 29
Most dialogs in Stata provide the same six buttons you see at the bottom of the poisson dialog
above.
OK issues a Stata command based on how you have filled out the fields in
the dialog and then closes the dialog.
Cancel closes the dialog without doing anything—just as clicking on the
dialog’s close button does.
Submit issues a command just like OK but leaves the dialog on the screen so
that you can make changes and issue another command. This feature is handy
when, for example, you are learning a new command or putting together a
complicated graph.
Help provides access to Stata’s help system. Clicking on this button will
typically take you to the help file for the Stata command associated with the
dialog. Clicking on it here would take you to the poisson help file. The help
file will have tabs above groups of options to show which dialog tab contains
which options.
Reset resets the dialog to its default state. Each time you open a dialog, it
will remember how you last filled it out. If you wish to reset its fields to their
default values at any time, simply click on this button.
Copy Command to Clipboard behaves much like the Submit button, but
rather than issuing a command, it copies the command to the Clipboard. The
command can then be pasted elsewhere (such as in the Do-file Editor).
The command issued by a dialog is submitted just as if you had typed it by hand. You can see
the command in the Results window and in the Review window after it executes. Looking carefully
at the full command will help you learn Stata’s command syntax.
In addition to being able to access the dialogs for Stata commands through Stata’s menus, you
can also invoke them by using two other methods. You may know the name of a Stata command for
which you want to see a dialog, but you might not remember how to navigate to that command in
the menu system. Simply type db commandname to launch the dialog for commandname:
 
. db poisson
 
You will also find access to the dialog for a command in that command’s help file; see [GSW] 4 Getting
help for more details.
As you read this manual, we will present examples of Stata commands. You may type those
examples as presented, but you should also experiment with submitting those commands by using
their dialogs. Use the db command described above to quickly launch the dialog for any command
that you see in this manual.
The working directory
If you look at the screenshot on page 23, you will notice the status bar at the base of the main
Stata window that contains the name of the current working directory you set when you installed
Stata. We will use the directory C:UsersmydirDocuments in our examples; your exact directory
will differ. The current working directory is the folder where graphs and datasets will be saved when
typing commands such as save filename. It does not affect the behavior of menu-driven file actions
30 [ GSW ] 2 The Stata user interface
such as File  Save or File  Open.... Once you have started Stata, you can change the current
working directory with the cd command. See [D] cd for full details. Stata always displays the name
of the current working directory so that it is easy to tell where your graphs and datasets will be saved.
Fine control of Stata’s windows
When Stata is first launched, the Review, Results, Command, Variables, and Properties windows
appear within the main Stata window. The Review, Variables, and Command windows are initially
linked to one another and attached to the edges of the Stata window. They can be resized by dragging
on their edges. They even have two more features: you can drag them by their titlebars to reposition
them within the main window, and you can hide them as tabs when not in use. To do so, click on
the pushpin icons in their titlebars.
The Results window always occupies whatever space remains inside the main Stata window.
All other windows that open up can be moved freely and independently of the Stata window.
This default behavior is simple and familiar and needs little explanation. Try playing with the
windows inside the main Stata window now. If you find that the window behavior is good, you can
stop reading this section. If you find that you would like some extra customization or that you would
simply like some technical explanation of added window behaviors, keep reading.
Window types
The Stata for Windows interface has two types of windows: docking and nondocking. The Review,
Command, Variables, and Properties windows are docking windows. All other windows are nondocking.
Docking windows have special characteristics that allow them to be used with other docking
windows: they can be linked (sharing a window with a splitter dividing the windows) or tabbed
(sharing a window with a tab for each docking window). They can be set to automatically hide when
not needed. Nondocking windows have none of these special characteristics.
Here is a brief comparison of the two types of windows:
Docking windows
• can be linked to other docking windows so that they share a window with a splitter dividing
them;
• can share one window with other docking windows with a tab for each;
• can be dragged in and out of the main Stata window or other docking windows;
• can be made to hide automatically when not in use; and
• can be made to always appear in front of the main Stata window.
Nondocking windows
• are separate from the main Stata window (except for the Results window);
• cannot be linked to other windows;
• cannot be tabbed to another window; and
• cannot be made to hide automatically when not in use.
When Stata is first launched, the Review, Results, Command, Variables, and Properties windows
appear within the main Stata window. The Review, Command, Variables, and Properties windows are
docking windows and are initially both docked and linked to one another. The Results window is a
nondocking window.
[ GSW ] 2 The Stata user interface 31
Docking windows
To allow docking windows to have extra features, select Edit  Preferences  General Preferences...,
click on the Windowing tab, and check Allow dockable windows to be undocked. Until this is selected,
the various windows will remain docked on the edges of the main Stata window.
Docking windows can be dragged into (docked) and out of (undocked) the main Stata window or
other docking windows. When you drag a docking window, a transparent blue box appears in place
of the window. If you drag the box over the main Stata window or another docking window, docking
guides appear (see figure 1). Dragging the box over a guide previews how and where the window
will appear if you release the mouse button. Releasing the mouse button (dropping) when the box is
over a guide (dropping) links or tabs the window as previewed, whereas releasing it when the box is
not over a docking guide simply moves the window to that position.
Dropping the box on one of the outer docking guides links the docking window to the window
under the guide. For example, figure 1 shows how you would drag the Review window over the
Variables window, at which point the docking guides appear. When you move the mouse over the
bottom docking guide and release the mouse button, the Review window becomes linked to the
Variables window and is displayed in the lower part of the window.
When docking windows are linked, a divider (splitter) is inserted between them. The splitter allows
the linked windows to be resized; increasing the size of one window decreases the size of the other. To
prevent splitters from resizing linked windows, select Edit  Preferences  General Preferences...,
click on the Windowing tab, and check Lock splitters. To undock a linked window, double-click on
the window’s title bar or drag the window away from the other window.
Figure 1: Linking two windows
Dropping the box on the center docking guide (see figure 2) combines the docking window with
the window under the guide. One docking window is created with a tab for each docked window at
the bottom of the new window. Clicking on a tab displays its window. To undock a tabbed window,
double-click on the window’s tab, or click and drag the window’s tab out of the docking window.
The docking window containing the tabbed windows can also be linked to other docking windows.
Figure 2: Docking two windows
32 [ GSW ] 2 The Stata user interface
Auto Hide and pinning
Docking windows support the Auto Hide feature, which automatically hides the docking windows
when they are not in use. When this feature is enabled, a pushpin will appear in the title bar of all
docked windows in the main Stata window.
To enable Auto Hide for a docking window, click on the pushpin in the title bar (see figure 3) so
that the pushpin is horizontal. Click on the pushpin again to disable Auto Hide; the pushpin will be
vertical.
After you enable Auto Hide for a docking window, the window is hidden when not in use and is
displayed as a tab along an edge of the main Stata window. To show the window, move the mouse
pointer over the tab. To hide the window again, move the mouse pointer outside the window. If the
window has the focus (its title bar is highlighted), it will be hidden if you click on another window.
Auto Hide works only on docking windows that are docked within the main Stata window.
Figure 3: Enabling Auto Hide
When you undock a docking window, you can move it in front of or behind other Stata windows,
including the main Stata window. If you click on any part of the main Stata window, the main window
will move to the front and obscure the undocked window. You can bring the undocked window
back to the front by selecting it from the Window menu. Or you can just make undocked windows
always appear in front of the main Stata window (float) by selecting Edit  Preferences  General
Preferences..., clicking on the Windowing tab, and checking Float dialogs and undocked-dockable
windows.
In addition to dragging the window, you can dock or undock a docking window by double-clicking
on its title bar. You can double-click on the title bar again to move the window back to its previously
docked or undocked location.
If you enable Auto Hide for the Review window in its default docked location, it will obscure any
text at the beginning of the Command window when it is displayed. To avoid this problem, dock this
window at the right edge of the main Stata window before enabling Auto Hide.
Nondocking windows
Nondocking windows include the Graph window, Data Editor, Do-file Editor, Viewers, and dialogs.
These windows are always independent of the main Stata window. The Results window, because of
its status as the primary window of Stata, must remain inside the main Stata window.
3 Using the Viewer
The Viewer’s purpose
The Viewer is a versatile tool in Stata. It will be the first place you can turn for help within Stata,
but it is far more than just a help system. You can also use the Viewer to add, delete, and manage
third-party extensions to Stata that are known as user-written programs; to view and print Stata logs
from both your current and your previous Stata sessions; to view and print any other Stata-formatted
(SMCL) or plain-text file; and even to launch your web browser to follow hyperlinks.
This chapter focuses on the general use of the Viewer, its buttons, and a brief summary of the
commands that the Viewer understands. There is more information about using the Viewer to find
help in [GSW] 4 Getting help and for installing user-written commands in [GSW] 19 Updating and
extending Stata—Internet functionality.
To open a new Viewer window, you may either click on the Viewer button, , or select Window
 Viewer  New Viewer. A Viewer opened by these means provides links that allow you to perform
several tasks.
33
34 [ GSW ] 3 Using the Viewer
Viewer buttons
The toolbar of the Viewer has multiple buttons, a command box, and a search box.
Back goes back one step in your viewing trail.
Forward goes forward one step in your viewing trail, as-
suming you backtracked.
Refresh refreshes the Viewer, in case you are viewing some-
thing that has changed since you opened the Viewer.
Print prints the contents of the Viewer.
Find opens the find bar at the bottom of the Viewer (see
below).
Search Chooses the scope of help searches in the Viewer.
The Find bar is used to find text within the current Viewer. To reveal the Find bar at the bottom
of the window, click on the Find button (see above):
The Find bar has its own buttons, fields, and checkboxes.
Close closes the Find bar.
Find is the field for entering the search text you would like
to find. You can change the search options by using the
checkboxes.
Next jumps to the next instance of the search text; it au-
tomatically wraps past the end of the Viewer document if
there are no further instances of the search text.
Previous jumps to the previous instance of the search text;
it automatically wraps past the start of the Viewer document
if there are no previous instances of the search text.
Highlight All highlights other instances of the search text (in
yellow, by default) when this box is checked. If unchecked,
only the current instance of the search text is highlighted (in
black, by default). By default, this box is checked.
Match Case, when checked, considers uppercase and low-
ercase letters to be different. When this box is checked,
searching for This would not find this. If unchecked, up-
percase and lowercase letters are considered the same, so
searching for This would find this. By default, this box
is unchecked.
[ GSW ] 3 Using the Viewer 35
Viewer’s function
The Viewer is similar to a web browser. It has links (shown in blue text) that you can click on
to see related help topics and to install and manage third-party software. When you move the mouse
pointer over a link, the status bar at the bottom of the Viewer shows the action associated with that
link. If the action of a link is help logistic, clicking on that link will show the help file for the
logistic command in the Viewer. Middle-clicking on a link in a Viewer window (if you do not have
a three-button mouse, then Shift+clicking) will open the link in a new Viewer window. Ctrl+clicking
will open the link in a new tab in the current Viewer window.
You can open a new Viewer by selecting Window  Viewer  New Viewer or by clicking on the
Viewer button on the toolbar. Entering a help command from the Command window will also open
a new Viewer.
To bring a Viewer to the front of all other Viewers, select Window  Viewer and choose a Viewer
from the list there. Selecting Close All Viewers closes all open Viewer windows.
Viewing local text files, including SMCL files
In addition to viewing built-in Stata help files, you can use the Viewer to view Stata Markup
and Control Language (SMCL) files such as those typically produced when logging your work (see
[GSW] 16 Saving and printing results by using logs) as well as plain-text files. To open a file and
view its contents, simply select File  View..., and you will be presented with a dialog:
You may either type in the name of the file that you wish to view and click on OK, or you may
click on the Browse... button to open a standard file dialog that allows you to navigate to the file.
If you currently have a log file open, you may view the log file in the Viewer. This method has
one advantage over scrolling back in the Results window: what you view stays fixed even as output
is added to the Results window. If you wish to view a current log file, select File  Log  View...,
and the usual dialog will appear but with the path and filename of the current log already in the
field. Simply click on OK, and the log will appear in the Viewer. See [GSW] 16 Saving and printing
results by using logs for more details.
Viewing remote files over the Internet
If you want to look at a remote file over the Internet, the process is similar to viewing a local file,
only instead of using the Browse... button, you type the URL of the file that you want to see, such as
http://www.stata.com/man/readme.smcl. You should use the Viewer only to view text or SMCL files.
If you enter the URL of, say, an arbitrary webpage, you will see the HTML source of the page instead
of the usual browser rendering.
36 [ GSW ] 3 Using the Viewer
Navigating within the Viewer
In addition to using the scrollbar to navigate the Viewer window, you also can use the up and
down arrow keys and Page Up and Page Down keys to do the same. Pressing the up or down arrow
key scrolls the window a line at a time. Pressing the Page Up or Page Down key scrolls the window
a screen at a time.
Printing
To print the contents of the Viewer, right-click on the window and select Print.... You may also
select File  Print  Viewer name or click on the arrow of the Print toolbar button to select from a
menu of open windows to print.
Tabs in the Viewer
The Viewer window can have multiple tabs. You may view different files or different views of
the same file in different tabs. Clicking on the Open New Tab button, , will open a new tab in
the current Viewer window. You can change the order of the tabs within a Viewer by dragging the
tabs along the tab bar within the window. If you drag a tab and drop it within the body of the same
Viewer window, a menu will appear. If you select New Horizontal Tab Group, the Viewer window
will be split horizontally. This is useful for having two views of the same file at different places in
the file. Similarly, if you select New Vertical Tab Group, the Viewer window will be split vertically.
This is useful for comparing two similar files side by side.
Once you have created a horizontal or vertical tab group, if you drop a tab inside a group, you
will get the choice of creating a similar new group or moving the tab to the selected group.
Right-clicking on the Viewer window
Right-clicking on the Viewer window displays a contextual menu that offers these options:
• Select All to select all text in the Viewer.
• Preferences... to edit the preferences for the Viewer window.
• Font... to change the font for the window.
• Print... to print the contents of the Viewer window.
Searching for help in the Viewer
The search box in the Viewer can be used to search documentation. Click on the magnifying glass;
choose Search all, Search documentation and FAQs, or Search net resources; and then type a word
or phrase in the search box and press Enter. For more extensive information about using the Viewer
for help, see [GSW] 4 Getting help.
Commands in the Viewer
Everything that can be done in the Viewer by clicking on links and buttons can also be done by
typing commands in the command box at the top of the window or on the Stata command line. Some
tasks that can be performed in the Viewer are
[ GSW ] 3 Using the Viewer 37
• obtaining help (see [GSW] 4 Getting help):
Type contents to view the contents of Stata’s help system.
Type commandname to view the help file for a Stata command.
• searching (see [GSW] 4 Getting help):
Type search keyword to search documentation, FAQs, and net resources for a topic.
Type search keyword, local to search only documentation and FAQs for a topic.
Type search keyword, net to search only net resources for a topic.
• finding and installing User-written programs (see [GSW] 4 Getting help and [GSW] 19 Updating
and extending Stata—Internet functionality):
Type net from http://www.stata.com/ to find and install Stata Journal, Stata Technical
Bulletin, and user-written programs from the Internet.
Type ado to review user-written programs you have installed.
Type ado uninstall to uninstall user-written programs you have installed on your
computer.
• viewing files in the Viewer:
Type view filename.smcl to view SMCL files.
Type view filename.txt to view text files.
Type view filename.log to view text log files.
• viewing files in the Results window:
Type type filename.smcl in the Command window to view SMCL files in the Results
window.
Type type filename.txt in the Command window to view text files in the Results
window.
Type type filename.log in the Command window to view text log files in the Results
window.
• launching your browser to view an HTML file:
Type browse URL to launch your browser.
• keeping informed:
Type news to see the latest news from http://www.stata.com.
Using the Viewer from the Command window
Typing help commandname in the Command window will bring up a new Viewer showing the
requested help.
4 Getting help
System help
Stata’s help system provides a wealth of information to help you learn and use Stata. To find out
which Stata command will perform the statistical or data management task you would like to do, you
should generally follow these steps:
1. Select Help  Search..., choose Search all, and enter the topic or keywords. This search will
open a new Viewer window containing information about Stata commands, references to articles
in the Stata Journal, links to Frequently Asked Questions (FAQs) on Stata’s website, links to
videos on Stata’s YouTube channel, links to selected external websites, and links to user-written
commands.
2. Read through the results. If you find a useful command, click on the link to the appropriate
command name to open its help file.
3. Read the help file for the command you chose.
4. If you want more in-depth help, click on the link from the name of the command to the PDF
documentation, read it, then come back to Stata.
5. If the first help file you went to is not what you wanted, either click on the Also See button
and choose a link to related help files or click on the Back button to go back to the previous
document and go from there to other help files.
6. With the help file open, click on the Command window and enter the command, or click on
the Dialog button and choose a link to open a dialog for the command.
7. If, at any time, you want to begin again with a new search, enter the new search terms in the
search box of the Viewer window.
8. If you select Search documentation and FAQs, Stata searches its keyword database for official
Stata commands, Stata Journal and STB articles and software, FAQs, and videos. If you select
Search net resources, Stata searches for user-written commands, whether they are from the
Stata Journal, the STB, or elsewhere; see [GSW] 19 Updating and extending Stata—Internet
functionality for more information.
Let’s illustrate the help system with an example. You will get the most benefit from the example
if you work along at your computer.
Suppose that we have been given a dataset about antique cars and that we need to know what
it contains. Though we still have a vague notion of having seen something like this while working
through the example session in [GSW] 1 Introducing Stata—sample session, we do not remember
the proper command.
Start by typing sysuse auto, clear in the Command window to bring the dataset into memory.
(See [GSW] 5 Opening and saving Stata datasets for information on the clear option.)
Following the above approach,
1. select Help  Search....
2. check that the Search all radio button is selected.
3. type dataset contents into the search box and click on OK or press Enter. Before we press
Enter, the window should look like
38
[ GSW ] 4 Getting help 39
4. Stata will now search for “dataset contents” among the Stata commands, the reference manuals,
the Stata Journal, the FAQs on Stata’s website, and user-written commands. Here is the result:
5. upon seeing the results of the search, we see two commands that look promising: codebook
and describe. Because we are interested in the contents of the dataset, we decide to check out
the codebook command. The [D] means that we could look up the codebook command in the
Data Management Reference Manual. The blue codebook link in (help codebook) means
that there is a system help file for the codebook command. This is what we are interested in
right now.
40 [ GSW ] 4 Getting help
6. click on the blue codebook link. Links can take you to a variety of resources, such as help
for Stata commands, dialogs, and even webpages. Here the link goes to the help file for the
codebook command.
7. what is displayed is typical for help for a Stata command. Help files for Stata commands
contain, from top to bottom, these features:
a. The quick access toolbar with three buttons:
i. The Dialog button shows links to any dialogs associated with the command.
ii. The Also See button shows links to related PDF documentation and help files.
iii. The Jump To button shows links to other sections within the current help file.
b. The very first link in the Title section is a link to the manual entry for the command in
the PDF documentation. Clicking on the link will open your PDF viewer and show you
the complete documentation for the command—in this case, codebook.
c. The command’s syntax, that is, rules for constructing a command that Stata will correctly
interpret. The square brackets here indicate that all the arguments to codebook are optional
but that if we wanted to specify them, we could use a varlist, an if qualifier, or an in
qualifier, along with some options. (Options vary greatly from command to command.)
The options are listed directly under the command and are explained in some detail later
in the help file. You will learn more about command syntax in [GSW] 10 Listing data
and basic command syntax.
d. A description of the command. Because “codebook” is the name for big binders containing
hard copy describing each of the elements of a dataset, the description for the codebook
command is justifiably terse.
e. The options that can be used with this command. These are explained in much greater
detail than in the listing of the possible options after the syntax. Here, for example, we can
see that the mv option can look to see if there is a pattern in the missing values—something
important for data cleaning and imputation.
[ GSW ] 4 Getting help 41
f. Examples of command usage. The codebook examples are real examples that step through
using the command on a dataset either shipped with Stata or loadable within Stata from
the Internet.
g. The information the command stores in the returned results. These results are used
primarily by programmers.
For now, either click on Jump To and choose Examples from the drop-down menu or scroll
down to the examples. It is worth going through the examples as given in the help file. Here is a
screenshot of the top of the examples:
Searching help
Search is designed to help you find information about statistics, graphics, data management, and
programming features in Stata, either as part of the official release or as user-written commands.
When entering topics for the search, use appropriate terms from statistics, etc. For example, you could
enter Mann-Whitney. Multiple topic words are allowed, for example, regression residuals.
When you are using Search, use proper English and proper statistical terminology. If you already
know the name of the Stata command and want to go directly to its help file, select Help  Stata
Command... and type the command name. You can also type the command name in the Search field
at the top of the Viewer and press Enter.
Help distinguishes between topics and Stata commands because some names of Stata commands
are also general topic names. For example, logistic is a Stata command. If you choose Stata
Command... and type logistic, you will go right to the help file for the command. But if you
choose Search... and type logistic, you will get search results listing the many Stata commands
that relate to logistic regression.
42 [ GSW ] 4 Getting help
Remember that you can search for help from within a Viewer window by typing a command in
the command box of the Viewer or by clicking the magnifying glass button to the left of the search
box, selecting the scope of your search, typing the search criteria in the search box, and pressing
Enter.
Help and search commands
As you might expect, the help system is accessible from the Command window. This feature is
especially convenient when you need help on a particular Stata command. Here is a short listing of
the various commands you can use:
• Typing help commandname is equivalent to selecting Help  Stata Command... and typing
commandname. The help file for the command appears in a new Viewer window.
• Typing search topic in the Command window produces the same output as selecting Help 
Search..., choosing Search all, and typing topic. The output appears in a new Viewer window.
• Typing search topic, local in the Command window produces the same output as selecting
Help  Search..., choosing Search documentation and FAQs, and typing topic. The output
appears in the Results window instead of a Viewer.
• Typing search topic, net in the Command window produces the same output as selecting
Help  Search..., choosing Search net resources, and typing topic. The output appears in the
Results window instead of a Viewer.
See [U] 4 Stata’s help and search facilities and [U] 4.8 search: All the details in the User’s
Guide for more information about these command-language versions of the help system. The search
command, in particular, has a few capabilities (such as author searches) that we have not demonstrated
here.
The Stata reference manuals and User’s Guide
All the Stata reference manuals come as PDF files and are included with the software. The manuals
themselves have many cross-references in the form of clickable links, so you can easily read the
documentation in a nonlinear way.
Many of the links in the help files point to the PDF manuals that came with Stata. It is worth
clicking on these links to read the extensive information found in the manuals. The Stata help system,
though extensive, contains only a fraction of the information found in the manuals.
The Stata reference manuals are each arranged like an encyclopedia, alphabetically, and each has
its own index. The User’s Guide also has an index. The Glossary and Index contains a combined
index for the User’s Guide and all the reference manuals. This combined index is a good place to
start when you are looking for information about a command.
Entries have names like collapse, egen, and summarize, which are generally themselves Stata
commands.
Notations such as [R] ci, [R] regress, and [R] ttest in the Search results and help files are references
to the Base Reference Manual. You may also see things like [P] #delimit, which is a reference to the
Programming Reference Manual, and [U] 9 The Break key, which is a reference to the User’s Guide.
For a complete list of manuals and their shorthand notations, see Cross-referencing the documentation,
which immediately follows the table of contents in this manual.
For advice on how to use the reference manuals, see [GSW] 18 Learning more about Stata, or
see [U] 1.2 The User’s Guide and the Reference manuals.
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13
Getting started with stata 13

More Related Content

What's hot

Rapid mart development guide
Rapid mart development guideRapid mart development guide
Rapid mart development guide
Bhaskar Reddy
 
NetApp system installation workbook Spokane
NetApp system installation workbook SpokaneNetApp system installation workbook Spokane
NetApp system installation workbook Spokane
Accenture
 
46600726 vijeo-quick-start-tutorial-v710
46600726 vijeo-quick-start-tutorial-v71046600726 vijeo-quick-start-tutorial-v710
46600726 vijeo-quick-start-tutorial-v710
croyf
 
Hp 40gs user's guide english
Hp 40gs user's guide englishHp 40gs user's guide english
Hp 40gs user's guide english
danilegg17
 
Precision Tracking System Design Process
Precision Tracking System Design ProcessPrecision Tracking System Design Process
Precision Tracking System Design Process
Daniel Medcraft
 
Plesk 8.1 for Linux/UNIX
Plesk 8.1 for Linux/UNIXPlesk 8.1 for Linux/UNIX
Plesk 8.1 for Linux/UNIX
webhostingguy
 

What's hot (20)

Rapid mart development guide
Rapid mart development guideRapid mart development guide
Rapid mart development guide
 
NetApp system installation workbook Spokane
NetApp system installation workbook SpokaneNetApp system installation workbook Spokane
NetApp system installation workbook Spokane
 
Blue Doc User Manual
Blue Doc   User ManualBlue Doc   User Manual
Blue Doc User Manual
 
Creating a VMware Software-Defined Data Center Reference Architecture
Creating a VMware Software-Defined Data Center Reference Architecture Creating a VMware Software-Defined Data Center Reference Architecture
Creating a VMware Software-Defined Data Center Reference Architecture
 
46600726 vijeo-quick-start-tutorial-v710
46600726 vijeo-quick-start-tutorial-v71046600726 vijeo-quick-start-tutorial-v710
46600726 vijeo-quick-start-tutorial-v710
 
Scholarship database management database (1)
Scholarship database management database (1)Scholarship database management database (1)
Scholarship database management database (1)
 
37274377 6260-manual
37274377 6260-manual37274377 6260-manual
37274377 6260-manual
 
Ibm spss decision_trees
Ibm spss decision_treesIbm spss decision_trees
Ibm spss decision_trees
 
Standars
StandarsStandars
Standars
 
CONTINUOUS SYSTEMS, NONSTOP OPERATIONS WITH JUNOS
CONTINUOUS SYSTEMS, NONSTOP OPERATIONS WITH JUNOSCONTINUOUS SYSTEMS, NONSTOP OPERATIONS WITH JUNOS
CONTINUOUS SYSTEMS, NONSTOP OPERATIONS WITH JUNOS
 
Aja ki pro_mini_manual_v4.1
Aja ki pro_mini_manual_v4.1Aja ki pro_mini_manual_v4.1
Aja ki pro_mini_manual_v4.1
 
Hp 40gs user's guide english
Hp 40gs user's guide englishHp 40gs user's guide english
Hp 40gs user's guide english
 
Rails4 Days
Rails4 DaysRails4 Days
Rails4 Days
 
E120
E120E120
E120
 
Precision Tracking System Design Process
Precision Tracking System Design ProcessPrecision Tracking System Design Process
Precision Tracking System Design Process
 
Cloud Infrastructure Architecture Case Study
Cloud Infrastructure Architecture Case StudyCloud Infrastructure Architecture Case Study
Cloud Infrastructure Architecture Case Study
 
Recovery oracle
Recovery oracleRecovery oracle
Recovery oracle
 
Dell Vostro 3568 Laptops Trần Phát
Dell Vostro 3568 Laptops Trần PhátDell Vostro 3568 Laptops Trần Phát
Dell Vostro 3568 Laptops Trần Phát
 
Plesk 8.1 for Linux/UNIX
Plesk 8.1 for Linux/UNIXPlesk 8.1 for Linux/UNIX
Plesk 8.1 for Linux/UNIX
 
Erpi admin 11123510[1] by иссам неязын issam hejazin
Erpi admin 11123510[1] by иссам неязын issam hejazinErpi admin 11123510[1] by иссам неязын issam hejazin
Erpi admin 11123510[1] by иссам неязын issam hejazin
 

Similar to Getting started with stata 13

Modifying infor erp_syte_line_5140
Modifying infor erp_syte_line_5140Modifying infor erp_syte_line_5140
Modifying infor erp_syte_line_5140
rajesh_rolta
 
01 introduction tovulcanmanual_v81_20120817-libre
01 introduction tovulcanmanual_v81_20120817-libre01 introduction tovulcanmanual_v81_20120817-libre
01 introduction tovulcanmanual_v81_20120817-libre
Walquer huacani calsin
 
Visual Studio 2008 Beginning Asp Net 3 5 In C# 2008 From Novice To Professi...
Visual Studio 2008   Beginning Asp Net 3 5 In C# 2008 From Novice To Professi...Visual Studio 2008   Beginning Asp Net 3 5 In C# 2008 From Novice To Professi...
Visual Studio 2008 Beginning Asp Net 3 5 In C# 2008 From Novice To Professi...
guest4c5b8c4
 
Analytics configuration reference_sc61_a4
Analytics configuration reference_sc61_a4Analytics configuration reference_sc61_a4
Analytics configuration reference_sc61_a4
samsherwood
 

Similar to Getting started with stata 13 (20)

estaditca aplicada
estaditca aplicadaestaditca aplicada
estaditca aplicada
 
Youwe sap-ecc-r3-hana-e commerce-with-magento-mb2b-100717-1601-206
Youwe sap-ecc-r3-hana-e commerce-with-magento-mb2b-100717-1601-206Youwe sap-ecc-r3-hana-e commerce-with-magento-mb2b-100717-1601-206
Youwe sap-ecc-r3-hana-e commerce-with-magento-mb2b-100717-1601-206
 
Modifying infor erp_syte_line_5140
Modifying infor erp_syte_line_5140Modifying infor erp_syte_line_5140
Modifying infor erp_syte_line_5140
 
estaditca 2
estaditca 2estaditca 2
estaditca 2
 
HRpM_UG_731_HDS_M2
HRpM_UG_731_HDS_M2HRpM_UG_731_HDS_M2
HRpM_UG_731_HDS_M2
 
01 introduction tovulcanmanual_v81_20120817-libre
01 introduction tovulcanmanual_v81_20120817-libre01 introduction tovulcanmanual_v81_20120817-libre
01 introduction tovulcanmanual_v81_20120817-libre
 
Ibm spss bootstrapping
Ibm spss bootstrappingIbm spss bootstrapping
Ibm spss bootstrapping
 
Cockpit esp
Cockpit espCockpit esp
Cockpit esp
 
Visual Studio 2008 Beginning Asp Net 3 5 In C# 2008 From Novice To Professi...
Visual Studio 2008   Beginning Asp Net 3 5 In C# 2008 From Novice To Professi...Visual Studio 2008   Beginning Asp Net 3 5 In C# 2008 From Novice To Professi...
Visual Studio 2008 Beginning Asp Net 3 5 In C# 2008 From Novice To Professi...
 
Analytics configuration reference_sc61_a4
Analytics configuration reference_sc61_a4Analytics configuration reference_sc61_a4
Analytics configuration reference_sc61_a4
 
Sap setup guide
Sap setup guideSap setup guide
Sap setup guide
 
Saphanaadministrationguide
SaphanaadministrationguideSaphanaadministrationguide
Saphanaadministrationguide
 
pdf of R for Cloud Computing
pdf of R for Cloud Computing pdf of R for Cloud Computing
pdf of R for Cloud Computing
 
PSAT_Power_System_Analysis_Toolbox.pdf
PSAT_Power_System_Analysis_Toolbox.pdfPSAT_Power_System_Analysis_Toolbox.pdf
PSAT_Power_System_Analysis_Toolbox.pdf
 
Sap In-Memory IBM
Sap In-Memory IBMSap In-Memory IBM
Sap In-Memory IBM
 
hci10_help_sap_en.pdf
hci10_help_sap_en.pdfhci10_help_sap_en.pdf
hci10_help_sap_en.pdf
 
MK-99DF8208-03
MK-99DF8208-03MK-99DF8208-03
MK-99DF8208-03
 
B035-2447-220K.pdf
B035-2447-220K.pdfB035-2447-220K.pdf
B035-2447-220K.pdf
 
Presentation data center deployment guide
Presentation   data center deployment guidePresentation   data center deployment guide
Presentation data center deployment guide
 
0001
00010001
0001
 

More from Eduardo J Kwiecien

An overview of the current trends in precision pig farming technologies 2ma...
An overview of the current trends in precision pig farming technologies   2ma...An overview of the current trends in precision pig farming technologies   2ma...
An overview of the current trends in precision pig farming technologies 2ma...
Eduardo J Kwiecien
 
Herd level risk factors for bovine viral diarrhoea infection in cattle
Herd level risk factors for bovine viral diarrhoea infection in cattleHerd level risk factors for bovine viral diarrhoea infection in cattle
Herd level risk factors for bovine viral diarrhoea infection in cattle
Eduardo J Kwiecien
 

More from Eduardo J Kwiecien (14)

A comparison of public perceptions of physicians and veterinarians in the uni...
A comparison of public perceptions of physicians and veterinarians in the uni...A comparison of public perceptions of physicians and veterinarians in the uni...
A comparison of public perceptions of physicians and veterinarians in the uni...
 
Centrifuge infographic-2017-final
Centrifuge infographic-2017-finalCentrifuge infographic-2017-final
Centrifuge infographic-2017-final
 
Suggested guidelines for_immunohistochemical_techn
Suggested guidelines for_immunohistochemical_technSuggested guidelines for_immunohistochemical_techn
Suggested guidelines for_immunohistochemical_techn
 
Importancia del ldv galileo feb 2018
Importancia del ldv   galileo feb 2018Importancia del ldv   galileo feb 2018
Importancia del ldv galileo feb 2018
 
Bubaline brucellosis ivis 24jun2014
Bubaline brucellosis  ivis   24jun2014Bubaline brucellosis  ivis   24jun2014
Bubaline brucellosis ivis 24jun2014
 
An overview of the current trends in precision pig farming technologies 2ma...
An overview of the current trends in precision pig farming technologies   2ma...An overview of the current trends in precision pig farming technologies   2ma...
An overview of the current trends in precision pig farming technologies 2ma...
 
Ch7 uso de_muestras_de_leche_como_indicador_de_salud_y_vigilancia_de_enfermed...
Ch7 uso de_muestras_de_leche_como_indicador_de_salud_y_vigilancia_de_enfermed...Ch7 uso de_muestras_de_leche_como_indicador_de_salud_y_vigilancia_de_enfermed...
Ch7 uso de_muestras_de_leche_como_indicador_de_salud_y_vigilancia_de_enfermed...
 
Herd level risk factors for bovine viral diarrhoea infection in cattle
Herd level risk factors for bovine viral diarrhoea infection in cattleHerd level risk factors for bovine viral diarrhoea infection in cattle
Herd level risk factors for bovine viral diarrhoea infection in cattle
 
Las tecnicas de laboratorios en la brucelosis segunda edicion - 1976
Las tecnicas de laboratorios en la brucelosis   segunda edicion - 1976Las tecnicas de laboratorios en la brucelosis   segunda edicion - 1976
Las tecnicas de laboratorios en la brucelosis segunda edicion - 1976
 
Argentina brucelosis políticas sobre aplicación de vacunas para el control-...
Argentina brucelosis   políticas sobre aplicación de vacunas para el control-...Argentina brucelosis   políticas sobre aplicación de vacunas para el control-...
Argentina brucelosis políticas sobre aplicación de vacunas para el control-...
 
Preslauhter withdrawal drugs
Preslauhter withdrawal drugsPreslauhter withdrawal drugs
Preslauhter withdrawal drugs
 
Brucellosis in cattle interim manual for the veterinarian & aht sept2016
Brucellosis in cattle interim manual for the veterinarian & aht   sept2016Brucellosis in cattle interim manual for the veterinarian & aht   sept2016
Brucellosis in cattle interim manual for the veterinarian & aht sept2016
 
Ba wnb-espagnol-d10331
Ba wnb-espagnol-d10331Ba wnb-espagnol-d10331
Ba wnb-espagnol-d10331
 
Vigilancia sanit, unidad iii 1ra y 2da parte
Vigilancia sanit, unidad iii   1ra y 2da parteVigilancia sanit, unidad iii   1ra y 2da parte
Vigilancia sanit, unidad iii 1ra y 2da parte
 

Recently uploaded

Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
amitlee9823
 
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
amitlee9823
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
amitlee9823
 
Probability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter LessonsProbability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter Lessons
JoseMangaJr1
 
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 

Recently uploaded (20)

Anomaly detection and data imputation within time series
Anomaly detection and data imputation within time seriesAnomaly detection and data imputation within time series
Anomaly detection and data imputation within time series
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics Program
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
 
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24  Building Real-Time Pipelines With FLaNKDATA SUMMIT 24  Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Predicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science ProjectPredicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science Project
 
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
 
Probability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter LessonsProbability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter Lessons
 
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
 

Getting started with stata 13

  • 1. GETTING STARTED WITH STATA FOR WINDOWS R RELEASE 13 ® A Stata Press Publication StataCorp LP College Station, Texas
  • 2. ® Copyright c 1985–2013 StataCorp LP All rights reserved Version 13 Published by Stata Press, 4905 Lakeway Drive, College Station, Texas 77845 Typeset in TEX ISBN-10: 1-59718-114-5 ISBN-13: 978-1-59718-114-3 This manual is protected by copyright. All rights are reserved. No part of this manual may be reproduced, stored in a retrieval system, or transcribed, in any form or by any means—electronic, mechanical, photocopy, recording, or otherwise—without the prior written permission of StataCorp LP unless permitted subject to the terms and conditions of a license granted to you by StataCorp LP to use the software and documentation. No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted by this document. StataCorp provides this manual “as is” without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose. StataCorp may make improvements and/or changes in the product(s) and the program(s) described in this manual at any time and without notice. The software described in this manual is furnished under a license agreement or nondisclosure agreement. The software may be copied only in accordance with the terms of the agreement. It is against the law to copy the software onto DVD, CD, disk, diskette, tape, or any other medium for any purpose other than backup or archival purposes. The automobile dataset appearing on the accompanying media is Copyright c 1979 by Consumers Union of U.S., Inc., Yonkers, NY 10703-1057 and is reproduced by permission from CONSUMER REPORTS, April 1979. Icons other than the Stata icon are licensed from the Iconfactory, Inc. They remain property of the Iconfactory, Inc., and may not be reproduced or redistributed. Stata, , Stata Press, Mata, , and NetCourse are registered trademarks of StataCorp LP. Stata and Stata Press are registered trademarks with the World Intellectual Property Organization of the United Nations. NetCourseNow is a trademark of StataCorp LP. Other brand and product names are registered trademarks or trademarks of their respective companies. For copyright information about the software, type help copyright within Stata. The suggested citation for this software is StataCorp. 2013. Stata: Release 13. Statistical Software. College Station, TX: StataCorp LP.
  • 3. Contents 1 Introducing Stata—sample session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2 The Stata user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 3 Using the Viewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 4 Getting help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 5 Opening and saving Stata datasets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 6 Using the Data Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 7 Using the Variables Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 8 Importing data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 9 Labeling data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 10 Listing data and basic command syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 11 Creating new variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 12 Deleting variables and observations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 13 Using the Do-file Editor—automating Stata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 14 Graphing data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 15 Editing graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 16 Saving and printing results by using logs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 17 Setting font and window preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 18 Learning more about Stata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 19 Updating and extending Stata—Internet functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 A Troubleshooting Stata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 B Advanced Stata usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 C More on Stata for Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 Subject index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 i
  • 4.
  • 5. Cross-referencing the documentation When reading this manual, you will find references to other Stata manuals. For example, [U] 26 Overview of Stata estimation commands [R] regress [D] reshape The first example is a reference to chapter 26, Overview of Stata estimation commands, in the User’s Guide; the second is a reference to the regress entry in the Base Reference Manual; and the third is a reference to the reshape entry in the Data Management Reference Manual. All the manuals in the Stata Documentation have a shorthand notation: [GSM] Getting Started with Stata for Mac [GSU] Getting Started with Stata for Unix [GSW] Getting Started with Stata for Windows [U] Stata User’s Guide [R] Stata Base Reference Manual [D] Stata Data Management Reference Manual [G] Stata Graphics Reference Manual [XT] Stata Longitudinal-Data/Panel-Data Reference Manual [ME] Stata Multilevel Mixed-Effects Reference Manual [MI] Stata Multiple-Imputation Reference Manual [MV] Stata Multivariate Statistics Reference Manual [PSS] Stata Power and Sample-Size Reference Manual [P] Stata Programming Reference Manual [SEM] Stata Structural Equation Modeling Reference Manual [SVY] Stata Survey Data Reference Manual [ST] Stata Survival Analysis and Epidemiological Tables Reference Manual [TS] Stata Time-Series Reference Manual [TE] Stata Treatment-Effects Reference Manual: Potential Outcomes/Counterfactual Outcomes [I] Stata Glossary and Index [M] Mata Reference Manual iii
  • 6.
  • 7. About this manual This manual discusses Stata for Windows R . Stata for Mac R users should see Getting Started with Stata for Mac; Stata for Unix R users should see Getting Started with Stata for Unix. This manual is intended both for people who are completely new to Stata and for experienced Stata users new to Stata for Windows. Previous Stata users will also find it helpful as a tutorial on some new features in Stata for Windows. Following the numbered chapters are three appendixes with information specific to Stata for Windows. We provide several types of technical support to registered Stata users. [GSW] 4 Getting help describes the resources available to help you learn about Stata’s commands and features. One of these resources is the Stata website (http://www.stata.com), where you will find answers to frequently asked questions (FAQs) as well as other useful information. If you still have questions after looking at the Stata website and the other resources described in [GSW] 19 Updating and extending Stata—Internet functionality, you can contact us as described in [U] 3.9 Technical support. Using this manual The new user will get the most out of this book by treating it as an exercise book, working through each example at the computer. The material builds, so material from earlier chapters will often be used in later chapters. Bear in mind that Stata is a rich and deep statistical package—just as statistics itself is rich and deep. The time spent working the examples will be repaid with dividends when doing true statistical analyses. The experienced user may still have something to learn from this manual despite its name. We suggest looking through the chapters to see if there is anything new or forgotten. v
  • 8.
  • 9. 1 Introducing Stata—sample session Introducing Stata This chapter will run through a sample work session, introducing you to a few of the basic tasks that can be done in Stata, such as opening a dataset, investigating the contents of the dataset, using some descriptive statistics, making some graphs, and doing a simple regression analysis. As you would expect, we will only brush the surface of many of these topics. This approach should give you a sample of what Stata can do and how Stata works. There will be brief explanations along the way, with references to chapters later in this book as well as to the system help and other Stata manuals. We will run through the session by using both menus and dialogs and Stata’s commands so that you can become familiar with them both. Take a seat at your computer, put on some good music, and work along with the book. Sample session The dataset that we will use for this session is a set of data about vintage 1978 automobiles sold in the United States. To follow along by pointing and clicking, note that the menu items are given by Menu > Menu Item > Submenu Item > etc. To follow along by using the Command window, type the commands that follow a dot (.) in the boxed listings below into the small window labeled Command. When there is something of note about the structure of a command, it will be pointed out as a “Syntax note”. Start by loading the auto dataset, which is included with Stata. To use the menus, 1. Select File > Example Datasets.... 2. Click on Example datasets installed with Stata. 3. Click on use for auto.dta. The result of this command is fourfold: • The following output appears in the large Results window: . sysuse auto.dta (1978 Automobile Data) The output consists of a command and its result. The command, sysuse auto.dta, is bold and follows the period (.). The result, (1978 Automobile Data), is in the standard face here and is a brief description of the dataset. Note: If a command intrigues you, you can type help commandname in the Command window to find help. If you want to explore at any time, Help Search... can be informative. • The same command, sysuse auto.dta, appears in the tall Review window to the left. The Review window keeps track of all commands Stata has run, successful and unsuccessful. The commands can then easily be rerun. See [GSW] 2 The Stata user interface for more information. • A series of variables appears in the small Variables window to the upper right. 1
  • 10. 2 [ GSW ] 1 Introducing Stata—sample session • Some information about make, the first variable in the dataset, appears in the small Properties window to the lower right. You could have opened the dataset by typing sysuse auto in the Command window and pressing Enter. Try this now. sysuse is a command that loads (uses) example (system) datasets. As you will see during this session, Stata commands are often simple enough that it is faster to use them directly. This will be especially true once you become familiar with the commands you use the most in your daily use of Stata. Syntax note: In the above example, sysuse is the Stata command, whereas auto is the name of a Stata data file. Simple data management We can get a quick glimpse at the data by browsing them in the Data Editor. This can be done by clicking on the Data Editor (Browse) button, , or by selecting Data Data Editor Data Editor (Browse) from the menus or by typing the command browse. Syntax note: Here the command is browse and there are no other arguments. When the Data Editor opens, you can see that Stata regards the data as one rectangular table. This is true for all Stata datasets. The columns represent variables, whereas the rows represent observations. The variables have somewhat descriptive names, whereas the observations are numbered. The data are displayed in multiple colors—at first glance, it appears that the variables listed in black are numeric, whereas those that are in colors are text. This is worth investigating. Click on a cell under the make variable: the input box at the top displays the make of the car. Scroll to the right until you see the foreign variable. Click on one of its cells. Although the cell may display “Domestic”, the input box displays a 0. This shows that Stata can store categorical data as numbers but display human-readable text. This is done by what Stata calls value labels. Finally, under the rep78 variable, which looks to be numeric, there are some cells containing just a period (.). The periods correspond to missing values.
  • 11. [ GSW ] 1 Introducing Stata—sample session 3 Looking at the data in this fashion, though comfortable, lends little information about the dataset. It would be useful for us to get more details about what the data are and how the data are stored. Close the Data Editor by clicking on its close button. We can see the structure of the dataset by describing its contents. This can be done either by going to Data Describe data Describe data in memory or in a file in the menus and clicking on OK or by typing describe in the Command window and pressing Enter. Regardless of which method you choose, you will get the same result: . describe Contains data from C:Program FilesStata13/ado/base/a/auto.dta obs: 74 1978 Automobile Data vars: 12 13 Apr 2013 17:45 size: 3,182 (_dta has notes) storage display value variable name type format label variable label make str18 %-18s Make and Model price int %8.0gc Price mpg int %8.0g Mileage (mpg) rep78 int %8.0g Repair Record 1978 headroom float %6.1f Headroom (in.) trunk int %8.0g Trunk space (cu. ft.) weight int %8.0gc Weight (lbs.) length int %8.0g Length (in.) turn int %8.0g Turn Circle (ft.) displacement int %8.0g Displacement (cu. in.) gear_ratio float %6.2f Gear Ratio foreign byte %8.0g origin Car type Sorted by: foreign If your listing stops short, and you see a blue more at the base of the Results window, pressing the Spacebar or clicking on the blue more itself will allow the command to be completed. At the top of the listing, some information is given about the dataset, such as where it is stored on disk, how much memory it occupies, and when the data were last saved. The bold 1978 Automobile Data is the short description that appeared when the dataset was opened and is referred to as a data label by Stata. The phrase _dta has notes informs us that there are notes attached to the dataset. We can see what notes there are by typing notes in the Command window: . notes _dta: 1. from Consumer Reports with permission Here we see a short note about the source of the data. Looking back at the listing from describe, we can see that Stata keeps track of more than just the raw data. Each variable has the following: • A variable name, which is what you call the variable when communicating with Stata. Variable names are one type of Stata name. See [U] 11.3 Naming conventions. • A storage type, which is the way Stata stores its data. For our purposes, it is enough to know that types like, say, strnumber are string, or text, variables, whereas all others in this dataset
  • 12. 4 [ GSW ] 1 Introducing Stata—sample session are numeric. While there are none in this dataset, Stata also allows arbitrarily long strings, or strLs. strLs can even contain binary information. See [U] 12.4 Strings. • A display format, which controls how Stata displays the data in tables. See [U] 12.5 Formats: Controlling how data are displayed. • A value label (possibly). This is the mechanism that allows Stata to store numerical data while displaying text. See [GSW] 9 Labeling data and [U] 12.6.3 Value labels. • A variable label, which is what you call the variable when communicating with other people. Stata uses the variable label when making tables, as we will see. A dataset is far more than simply the data it contains. It is also information that makes the data usable by someone other than the original creator. Although describing the data tells us something about the structure of the data, it says little about the data themselves. The data can be summarized by clicking on Statistics Summaries, tables, and tests Summary and descriptive statistics Summary statistics and clicking on the OK button. You could also type summarize in the Command window and press Enter. The result is a table containing summary statistics about all the variables in the dataset: . summarize Variable Obs Mean Std. Dev. Min Max make 0 price 74 6165.257 2949.496 3291 15906 mpg 74 21.2973 5.785503 12 41 rep78 69 3.405797 .9899323 1 5 headroom 74 2.993243 .8459948 1.5 5 trunk 74 13.75676 4.277404 5 23 weight 74 3019.459 777.1936 1760 4840 length 74 187.9324 22.26634 142 233 turn 74 39.64865 4.399354 31 51 displacement 74 197.2973 91.83722 79 425 gear_ratio 74 3.014865 .4562871 2.19 3.89 foreign 74 .2972973 .4601885 0 1 From this simple summary, we can learn a bit about the data. First of all, the prices are nothing like today’s car prices—of course, these cars are now antiques. We can see that the gas mileages are not particularly good. Automobile aficionados can get a feel for other esoteric characteristics. There are two other important items here: • The make variable is listed as having no observations. It really has no numerical observations because it is a string (text) variable. • The rep78 variable has five fewer observations than the other numerical variables. This implies that rep78 has five missing values. Although we could use the summarize and describe commands to get a bird’s eye view of the dataset, Stata has a command that gives a good in-depth description of the structure, contents, and values of the variables: the codebook command. Either type codebook in the Command window and press Enter or navigate the menus to Data Describe data Describe data contents (codebook) and click on OK. We get a large amount of output that is worth investigating. In fact, we get more output than can fit on one screen, as can be seen by the blue more at the bottom of the Results window. Press the Spacebar a few times to get all the output to scroll past. (For more about more , see More in [GSW] 10 Listing data and basic command syntax.) Look over the output to see that
  • 13. [ GSW ] 1 Introducing Stata—sample session 5 much can be learned from this simple command. You can scroll back in the Results window to see earlier results, if need be. We will focus on the output for make, rep78, and foreign. To start our investigation, we would like to run the codebook command on just one variable, say, make. We can do this, as usual, with menus or the command line. To get the codebook output for make with the menus, start by navigating to Data Describe data Describe data contents (codebook). When the dialog appears, there are multiple ways to tell Stata to consider only the make variable: • We could type make into the Variables field. • The Variables field is a combobox control that accepts variable names. Clicking on the drop triangle to the right of the Variables field displays a list of the variables from the current dataset. Selecting a variable from the list will, in this case, enter the variable name into the edit field. A much easier solution is to type codebook make in the Command window and then press Enter. The result is informative: . codebook make make Make and Model type: string (str18), but longest is str17 unique values: 74 missing : 0/74 examples: Cad. Deville Dodge Magnum Merc. XR-7 Pont. Catalina warning: variable has embedded blanks The first line of the output tells us the variable name (make) and the variable label (Make and Model). The variable is stored as a string (which is another way of saying “text”) with a maximum length of 18 characters, though a size of only 17 characters would be enough. All the values are unique, so if need be, make could be used as an identifier for the observations—something that is often useful when putting together data from multiple sources or when trying to weed out errors from the dataset. There are no missing values, but there are blanks within the makes. This latter fact could be useful if we were expecting make to be a one-word string variable. Syntax note: Telling the codebook command to run on the make variable is an example of using a varlist in Stata’s syntax. Looking at the foreign variable can teach us about value labels. We would like to look at the codebook output for this variable, and on the basis of our latest experience, it would be easy to type codebook foreign into the Command window (from here on, we will not explicitly say to press the Enter key) to get the following output:
  • 14. 6 [ GSW ] 1 Introducing Stata—sample session . codebook foreign foreign Car type type: numeric (byte) label: origin range: [0,1] units: 1 unique values: 2 missing .: 0/74 tabulation: Freq. Numeric Label 52 0 Domestic 22 1 Foreign We can glean that foreign is an indicator variable because its only values are 0 and 1. The variable has a value label that displays Domestic instead of 0 and Foreign instead of 1. There are two advantages of storing the data in this form: • Storing the variable as a byte takes less memory because each observation uses 1 byte instead of the 8 bytes needed to store “Domestic”. This is important in large datasets. See [U] 12.2.2 Numeric storage types. • As an indicator variable, it is easy to incorporate into statistical models. See [U] 25 Working with categorical data and factor variables. Finally, we can learn a little about a poorly labeled variable with missing values by looking at the rep78 variable. Typing codebook rep78 into the Command window yields . codebook rep78 rep78 Repair Record 1978 type: numeric (int) range: [1,5] units: 1 unique values: 5 missing .: 5/74 tabulation: Freq. Value 2 1 8 2 30 3 18 4 11 5 5 . rep78 appears to be a categorical variable, but because of lack of documentation, we do not know what the numbers mean. (To see how we would label the values, see Changing data in [GSW] 6 Using the Data Editor and see [GSW] 9 Labeling data.) This variable has five missing values, meaning that there are five observations for which the repair record is not recorded. We could use the Data Editor to investigate these five observations, but we will do this by using the Command window only because doing so is much simpler. If you recall, the command brought up by clicking on the Data Editor (Browse) button was browse. We would like to browse only those observations for which rep78 is missing, so we could type
  • 15. [ GSW ] 1 Introducing Stata—sample session 7 . browse if missing(rep78) From this, we see that the . entries are indeed missing values. The . is the default numerical missing value; Stata also allows .a, . . . , .z as user missing values, but we do not have any in our dataset. See [U] 12.2.1 Missing values. Close the Data Editor after you are satisfied with this statement. Syntax note: Using the if qualifier above is what allowed us to look at a subset of the observations. Looking through the data lends no clues about why these particular data are missing. We decide to check the source of the data to see if the missing values were originally missing or if they were omitted in error. Listing the makes of the cars whose repair records are missing will be all we need because we saw earlier that the values of make are unique. This can be done with the menus and a dialog: 1. Select Data Describe data List data. 2. Click on the drop triangle to the right of the Variables field to show the variable names. 3. Click on make to enter it into the Variables field. 4. Click on the by/if/in tab in the dialog. 5. Type missing(rep78) into the If: (expression) box. 6. Click on Submit. Stata executes the proper command but the dialog remains open. Submit is useful when experimenting, exploring, or building complex commands. We will primarily use Submit in the examples. You may click on OK in its place if you like, and it will close the dialog box. The same ends could be achieved by typing list make if missing(rep78) in the Command window. The latter is easier once you know that the command list is used for listing observations. In any case, here is the output:
  • 16. 8 [ GSW ] 1 Introducing Stata—sample session . list make if missing(rep78) make 3. AMC Spirit 7. Buick Opel 45. Plym. Sapporo 51. Pont. Phoenix 64. Peugeot 604 We go to the original reference and find that the data were truly missing and cannot be resurrected. See [GSW] 10 Listing data and basic command syntax for more information about all that can be done with the list command. Syntax note: This command uses two new concepts for Stata commands—the if qualifier and the missing() function. The if qualifier restricts the observations on which the command runs to only those observations for which the expression is true. See [U] 11.1.3 if exp. The missing() function tests each observation to see if it contains a missing value. See [U] 13.3 Functions. Now that we have a good idea about the underlying dataset, we can investigate the data themselves. Descriptive statistics We saw above that the summarize command gave brief summary statistics about all the variables. Suppose now that we became interested in the prices while summarizing the data because they seemed fantastically low (it was 1978, after all). To get an in-depth look at the price variable, we can use the menus and a dialog: 1. Select Statistics Summaries, tables, and tests Summary and descriptive statistics Summary statistics. 2. Enter or select price in the Variables field. 3. Select Display additional statistics. 4. Click on Submit. Syntax note: As can be seen from the Results window, typing summarize price, detail will get the same result. The portion after the comma contains options for Stata commands; hence, detail is an example of an option.
  • 17. [ GSW ] 1 Introducing Stata—sample session 9 . summarize price, detail Price Percentiles Smallest 1% 3291 3291 5% 3748 3299 10% 3895 3667 Obs 74 25% 4195 3748 Sum of Wgt. 74 50% 5006.5 Mean 6165.257 Largest Std. Dev. 2949.496 75% 6342 13466 90% 11385 13594 Variance 8699526 95% 13466 14500 Skewness 1.653434 99% 15906 15906 Kurtosis 4.819188 From the output, we can see that the median price of the cars in the dataset is only $5,006.50! We can also see that the four most expensive cars are all priced between $13,400 and $16,000. If we wished to browse the most expensive cars (and gain some experience with features of the Data Editor), we could start by clicking on the Data Editor (Browse) button, . Once the Data Editor is open, we can click on the Filter Observations button, , to bring up the Filter Observations dialog. We can look at the expensive cars by putting price 13000 in the Filter by expression field: Pressing the Apply Filter button filters the data, and we can see that the expensive cars are two Cadillacs and two Lincolns, which were not designed for gas mileage:
  • 18. 10 [ GSW ] 1 Introducing Stata—sample session We now decide to turn our attention to foreign cars and repairs because as we glanced through the data, it appeared that the foreign cars had better repair records. (We do not know exactly what the categories 1, 2, 3, 4, and 5 mean, but we know the Chevy Monza was known for breaking down.) Let’s start by looking at the proportion of foreign cars in the dataset along with the proportion of cars with each type of repair record. We can do this with one-way tables. The table for foreign cars can be done with menus and a dialog starting with Statistics Summaries, tables, and tests Frequency tables One-way table and then choosing the variable foreign in the Categorical variable field. Clicking on Submit yields . tabulate foreign Car type Freq. Percent Cum. Domestic 52 70.27 70.27 Foreign 22 29.73 100.00 Total 74 100.00 We see that roughly 70% of the cars in the dataset are domestic, whereas 30% are foreign. The value labels are used to make the table so that the output is nicely readable. Syntax note: We also see that this one-way table could be made by using the tabulate command together with one variable, foreign. Making a one-way table for the repair records is simple—it will be simpler if done with the Command window. Typing tabulate rep78 yields . tabulate rep78 Repair Record 1978 Freq. Percent Cum. 1 2 2.90 2.90 2 8 11.59 14.49 3 30 43.48 57.97 4 18 26.09 84.06 5 11 15.94 100.00 Total 69 100.00 We can see that most cars have repair records of 3 and above, though the lack of value labels makes us unsure what a “3” means. Take our word for it that 1 means a poor repair record and 5 means a good
  • 19. [ GSW ] 1 Introducing Stata—sample session 11 repair record. The five missing values are indirectly evident because the total number of observations listed is 69 rather than 74. These two one-way tables do not help us compare the repair records of foreign and domestic cars. A two-way table would help greatly, which we can get by using the menus and a dialog: 1. Select Statistics Summaries, tables, and tests Frequency tables Two-way table with measures of association. 2. Choose rep78 as the Row variable. 3. Choose foreign as the Column variable. 4. It would be nice to have the percentages within the foreign variable, so check the Within-row relative frequencies checkbox. 5. Click on Submit. Here is the resulting output: . tabulate rep78 foreign, row Key frequency row percentage Repair Record Car type 1978 Domestic Foreign Total 1 2 0 2 100.00 0.00 100.00 2 8 0 8 100.00 0.00 100.00 3 27 3 30 90.00 10.00 100.00 4 9 9 18 50.00 50.00 100.00 5 2 9 11 18.18 81.82 100.00 Total 48 21 69 69.57 30.43 100.00 The output indicates that foreign cars are generally much better than domestic cars when it comes to repairs. If you like, you could repeat the previous dialog and try some of the hypothesis tests available from the dialog. We will abstain. Syntax note: We see that typing the command tabulate rep78 foreign, row would have given us the same table. Thus using tabulate with two variables yields a two-way table. It makes sense that row is an option—we went out of our way to check it in the dialog. Using the row option allows us to change the behavior of the tabulate command from its default. Continuing our exploratory tour of the data, we would like to compare gas mileages between foreign and domestic cars, starting by looking at the summary statistics for each group by itself. A direct way to do this would be to use if qualifiers to summarize mpg for each of the two values of foreign separately:
  • 20. 12 [ GSW ] 1 Introducing Stata—sample session . summarize mpg if foreign==0 Variable Obs Mean Std. Dev. Min Max mpg 52 19.82692 4.743297 12 34 . summarize mpg if foreign==1 Variable Obs Mean Std. Dev. Min Max mpg 22 24.77273 6.611187 14 41 It appears that foreign cars get somewhat better gas mileage—we will test this soon. Syntax note: We needed to use a double equal sign (==) for testing equality. The double equal sign could be familiar to you if you have programmed before. If it is unfamiliar, be aware that it is a common source of errors when initially using Stata. Thinking of equality as “exactly equal” can cut down on typing errors. There are two other methods that we could have used to produce these summary statistics. These methods are worth knowing because they are less error-prone. The first method duplicates the concept of what we just did by exploiting Stata’s ability to run a command on each of a series of nonoverlapping subsets of the dataset. To use the menus and a dialog, do the following: 1. Select Statistics Summaries, tables, and tests Summary and descriptive statistics Summary statistics and click on the Reset button, . 2. Select mpg in the Variables field. 3. Select the Standard display option (if it is not already selected). 4. Click on the by/if/in tab. 5. Check the Repeat command by groups checkbox. 6. Select or type foreign in the Variables that define groups field. 7. Submit the command. You can see that the results match those from above. They have a better appearance than the two commands above because the value labels Domestic and Foreign are used rather than the numerical values. The method is more appealing because the results were produced without needing to know the possible values of the grouping variable ahead of time. . by foreign, sort : summarize mpg - foreign = Domestic Variable Obs Mean Std. Dev. Min Max mpg 52 19.82692 4.743297 12 34 - foreign = Foreign Variable Obs Mean Std. Dev. Min Max mpg 22 24.77273 6.611187 14 41 Syntax note: There is something different about the equivalent command that appears above: it contains a prefix command called a by prefix. The by prefix has its own option, namely, sort, to ensure that like members are adjacent to each other before being summarized. The by prefix command is important for understanding data manipulation and working with subpopulations within Stata. Make good note of this example, and consult [U] 11.1.2 by varlist: and [U] 27.2 The by construct for more
  • 21. [ GSW ] 1 Introducing Stata—sample session 13 information. Stata has other prefix commands for specialized treatment of commands, as explained in [U] 11.1.10 Prefix commands. The third method for tabulating the differences in gas mileage across the cars’ origins involves thinking about the structure of desired output. We need a one-way table of automobile types (foreign versus domestic) within which we see information about gas mileages. Looking through the menus yields the menu item Statistics Summaries, tables, and tests Other tables Table of means, std. dev., and frequencies. Selecting this, entering foreign for Variable 1 and mpg for the Summarize variable, and submitting the command yields a nice table: . tabulate foreign, summarize(mpg) Summary of Mileage (mpg) Car type Mean Std. Dev. Freq. Domestic 19.826923 4.7432972 52 Foreign 24.772727 6.6111869 22 Total 21.297297 5.7855032 74 The equivalent command is evidently tabulate foreign, summarize(mpg). Syntax note: This is a one-way table, so tabulate uses one variable. The variable being summarized is passed to the tabulate command with an option. Though we will not do it here, the summarize() option can also be used with two-way tables. A simple hypothesis test We would like to run a hypothesis test for the difference in the mean gas mileages. Under the menus, Statistics Summaries, tables, and tests Classical tests of hypotheses t test (mean-comparison test) leads to the proper dialog. Select the Two-sample using groups radio button, enter mpg for the Variable name and foreign for the Group variable name, and Submit the dialog. The results are . ttest mpg, by(foreign) Two-sample t test with equal variances Group Obs Mean Std. Err. Std. Dev. [95% Conf. Interval] Domestic 52 19.82692 .657777 4.743297 18.50638 21.14747 Foreign 22 24.77273 1.40951 6.611187 21.84149 27.70396 combined 74 21.2973 .6725511 5.785503 19.9569 22.63769 diff -4.945804 1.362162 -7.661225 -2.230384 diff = mean(Domestic) - mean(Foreign) t = -3.6308 Ho: diff = 0 degrees of freedom = 72 Ha: diff 0 Ha: diff != 0 Ha: diff 0 Pr(T t) = 0.0003 Pr(|T| |t|) = 0.0005 Pr(T t) = 0.9997 From this, we could conclude that the mean gas mileage for foreign cars is different from that of domestic cars (though we really ought to have wanted to test this before snooping through the data). We can also conclude that the command, ttest mpg, by(foreign), is easy enough to remember. Feel free to experiment with unequal variances, various approximations to the number of degrees of freedom, and the like.
  • 22. 14 [ GSW ] 1 Introducing Stata—sample session Syntax note: The by() option used here is not the same as the by prefix command used earlier. Although it has a similar conceptual meaning, its usage is different because it is a particular option for the ttest command. Descriptive statistics—correlation matrices We now change our focus from exploring categorical relationships to exploring numerical relation- ships: we would like to know if there is a correlation between miles per gallon and weight. We select Statistics Summaries, tables, and tests Summary and descriptive statistics Correlations and covariances in the menus. Entering mpg and weight, either by clicking or by typing, and then submitting the command yields . correlate mpg weight (obs=74) mpg weight mpg 1.0000 weight -0.8072 1.0000 The equivalent command for this is natural: correlate mpg weight. There is a negative correlation, which is not surprising because heavier cars should be harder to push about. We could see how the correlation compares for foreign and domestic cars by using our knowledge of the by prefix. We can reuse the correlate dialog or use the menus as before if the dialog is closed. Click on the by/if/in tab, check the Repeat command by groups checkbox, and enter the foreign variable to define the groups. As done on page 12, a simple by foreign, sort: prefix in front of our previous command would work, too: . by foreign, sort: correlate mpg weight - foreign = Domestic (obs=52) mpg weight mpg 1.0000 weight -0.8759 1.0000 - foreign = Foreign (obs=22) mpg weight mpg 1.0000 weight -0.6829 1.0000 We see from this that the correlation is not as strong among the foreign cars. Syntax note: Although we used the correlate command to look at the correlation of two variables, Stata can make correlation matrices for an arbitrary number of variables:
  • 23. [ GSW ] 1 Introducing Stata—sample session 15 . correlate mpg weight length turn displacement (obs=74) mpg weight length turn displa~t mpg 1.0000 weight -0.8072 1.0000 length -0.7958 0.9460 1.0000 turn -0.7192 0.8574 0.8643 1.0000 displacement -0.7056 0.8949 0.8351 0.7768 1.0000 This can be useful, for example, when investigating collinearity among predictor variables. Graphing data We have found several things in our investigations so far: We know that the average MPG of domestic and foreign cars differs. We have learned that domestic and foreign cars differ in other ways as well, such as in frequency-of-repair record. We found a negative correlation between MPG and weight—as we would expect—but the correlation appears stronger for domestic cars. We would now like to examine, with an eye toward modeling, the relationship between MPG and weight, starting with a graph. We can start with a scatterplot of mpg against weight. The command for this is simple: scatter mpg weight. Using the menus requires a few steps because the graphs in Stata may be customized heavily. 1. Select Graphics Twoway graph (scatter, line, etc.). 2. Click on the Create... button. 3. Select the Basic plots radio button (if it is not already selected). 4. Select Scatter as the basic plot type (if it is not already selected). 5. Select mpg as the Y variable and weight as the X variable. 6. Click on the Submit button. The Results window shows the command that was issued from the menu: . twoway (scatter mpg weight) The command issued when the dialog was submitted is a bit more complex than the command suggested above. There is good reason for this: the more complex structure allows combining and overlaying graphs, as we will soon see. In any case, the graph that appears is
  • 24. 16 [ GSW ] 1 Introducing Stata—sample session 10 20 30 40 Mileage (mpg) 2,000 3,000 4,000 5,000 Weight (lbs.) We see the negative correlation in the graph, though the relationship appears to be nonlinear. Note: When you draw a graph, the Graph window appears, probably covering up your Results window. Click on the main Stata window to get the Results window back on top. Want to see the graph again? Click on the Graph button, . See The Graph button in [GSW] 14 Graphing data for more information about the Graph button. We would now like to see how the different correlations for foreign and domestic cars are manifested in scatterplots. It would be nice to see a scatterplot for each type of car, along with a scatterplot for all the data. Syntax note: Because we are looking at subgroups, this looks as if it is a job for the by prefix. Let’s see if this is what we really should use. Start as before: 1. Select Graphics Twoway graph (scatter, line, etc.) from the menus. 2. If the Plot 1 dialog is still visible, click on the Accept button and skip to step 4. 3. Go through the process on the previous page to create the graph. 4. Click on the By tab of the twoway - Twoway graphs dialog. 5. Check the Draw subgraphs for unique values of variables checkbox. 6. Enter foreign in the Variables field. 7. Check the Add a graph with totals checkbox. 8. Click on the Submit button.
  • 25. [ GSW ] 1 Introducing Stata—sample session 17 The command and the associated graph are . twoway (scatter mpg weight), by(foreign, total) 10 20 30 40 10 20 30 40 2,000 3,000 4,000 5,000 2,000 3,000 4,000 5,000 Domestic Foreign Total Mileage (mpg) Weight (lbs.) Graphs by Car type The graphs show that the relationship is nonlinear for both types of cars. Syntax note: To make the graphs for the combined subgroups, we ended up using a by() option, not a by prefix. If we had used a by prefix, separate graphs would have been generated instead of the combined graph created by the by() option. Model fitting: Linear regression After looking at the graphs, we would like to fit a regression model that predicts MPG from the weight and type of the car. From the graphs, we see that the relationship is nonlinear, so we will try modeling MPG as a quadratic in weight. Also from the graphs, we judge the relationship to be different for domestic and foreign cars. We will include an indicator (dummy) variable for foreign and evaluate afterward whether this adequately describes the difference. Thus we will fit the model mpg = β0 + β1 weight + β2 weight2 + β3 foreign + foreign is already an indicator (0/1) variable, but we need to create the weight-squared variable. This can be done with the menus, but here using the command line is simpler. Type . generate wtsq = weight^2
  • 26. 18 [ GSW ] 1 Introducing Stata—sample session Now that we have all the variables we need, we can run a linear regression. We will use the menus and see that the command is also simple. To use the menus, select Statistics Linear models and related Linear regression. In the resulting dialog, choose mpg as the Dependent variable and weight, wtsq, and foreign as the Independent variables. Submit the command. Here is the equivalent simple regress command and the resulting analysis-of-variance table. . regress mpg weight wtsq foreign Source SS df MS Number of obs = 74 F( 3, 70) = 52.25 Model 1689.15372 3 563.05124 Prob F = 0.0000 Residual 754.30574 70 10.7757963 R-squared = 0.6913 Adj R-squared = 0.6781 Total 2443.45946 73 33.4720474 Root MSE = 3.2827 mpg Coef. Std. Err. t P|t| [95% Conf. Interval] weight -.0165729 .0039692 -4.18 0.000 -.0244892 -.0086567 wtsq 1.59e-06 6.25e-07 2.55 0.013 3.45e-07 2.84e-06 foreign -2.2035 1.059246 -2.08 0.041 -4.3161 -.0909002 _cons 56.53884 6.197383 9.12 0.000 44.17855 68.89913 The results look encouraging, so we will plot the predicted values on top of the scatterplots for each of the types of cars. To do this, we need the predicted, or fitted, values. This can be done with the menus, but doing it in the Command window is simple enough. We will create a new variable, mpghat to hold the predicted MPG for each car. Type . predict mpghat (option xb assumed; fitted values) The output from this command is simply a notification. Go over to the Variables window and scroll to the bottom to confirm that there is now an mpghat variable. If you were to try this command when mpghat already existed, Stata would refuse to overwrite your data: . predict mpghat mpghat already defined r(110); The predict command, when used after a regression, is called a postestimation command. As specified, it creates a new variable called mpghat equal to −0.0165729 weight + 1.59 × 10−6 wtsq − 2.2035 foreign + 56.53884 For careful model fitting, there are several features available to you after estimation—one is calculating predicted values. Be sure to read [U] 20 Estimation and postestimation commands. We can now graph the data and the predicted curve to evaluate separately the fit on the foreign and domestic data to determine if our shift parameter is adequate. We can draw both graphs together. Using the menus and a dialog, do the following: 1. Select Graphics Twoway graph (scatter, line, etc.) from the menus. 2. If there are any plots listed, click on the Reset button, , to clear the dialog box.
  • 27. [ GSW ] 1 Introducing Stata—sample session 19 3. Create the graph for mpg versus weight: a. Click on the Create... button. b. Be sure that Basic plots and Scatter are selected. c. Select mpg as the Y variable and weight as the X variable. d. Click on Accept. 4. Create the graph showing mpghat versus weight a. Click on the Create... button. b. Select Basic plots and Line. c. Select mpghat as the Y variable and weight as the X variable. d. Check the Sort on x variable box. Doing so ensures that the lines connect from smallest to largest weight values, instead of the order in which the data happen to be. e. Click on Accept. 5. Show two plots, one each for domestic and foreign cars, on the same graph: a. Click on the By tab. b. Check the Draw subgraphs for unique values of variables checkbox. c. Enter foreign in the Variables field. 6. Click on the Submit button. Here are the resulting command and graph: . twoway (scatter mpg weight) (line mpghat weight, sort), by(foreign) 10 20 30 40 2,000 3,000 4,000 5,000 2,000 3,000 4,000 5,000 Domestic Foreign Mileage (mpg) Fitted values Weight (lbs.) Graphs by Car type
  • 28. 20 [ GSW ] 1 Introducing Stata—sample session Here we can see the reason for enclosing the separate scatter and line commands in parentheses: they can thereby be overlaid by submitting them together. The fit of the plots looks good and is cause for initial excitement. So much excitement, in fact, that we decide to print the graph and show it to an engineering friend. We print the graph, being careful to print the graph (and not all our results), by choosing File Print... from the Graph window menu bar. When we show our graph to our engineering friend, she is concerned. “No,” she says. “It should take twice as much energy to move 2,000 pounds 1 mile compared with moving 1,000 pounds the same distance: therefore, it should consume twice as much gasoline. Miles per gallon is not quadratic in weight; gallons per mile is a linear function of weight. Don’t you remember any physics?” We try out what she says. We need to generate an energy-per-distance variable and make a scatterplot. Here are the commands that we would need—note their similarity to commands issued earlier in the session. There is one new command, the label variable command, which allows us to give the gpm100m variable a variable label so that the graph is labeled nicely. . generate gp100m = 100/mpg . label variable gp100m Gallons per 100 miles . twoway (scatter gp100m weight), by(foreign, total) 2 4 6 8 2 4 6 8 2,000 3,000 4,000 5,000 2,000 3,000 4,000 5,000 Domestic Foreign Total Gallons per 100 miles Weight (lbs.) Graphs by Car type
  • 29. [ GSW ] 1 Introducing Stata—sample session 21 Sadly satisfied that the engineer is indeed correct, we rerun the regression: . regress gp100m weight foreign Source SS df MS Number of obs = 74 F( 2, 71) = 113.97 Model 91.1761694 2 45.5880847 Prob F = 0.0000 Residual 28.4000913 71 .400001287 R-squared = 0.7625 Adj R-squared = 0.7558 Total 119.576261 73 1.63803097 Root MSE = .63246 gp100m Coef. Std. Err. t P|t| [95% Conf. Interval] weight .0016254 .0001183 13.74 0.000 .0013896 .0018612 foreign .6220535 .1997381 3.11 0.003 .2237871 1.02032 _cons -.0734839 .4019932 -0.18 0.855 -.8750354 .7280677 We find that foreign cars had better gas mileage than domestic cars in 1978 because they were so light. According to our model, a foreign car with the same weight as a domestic car would use an additional 5/8 gallon (or 5 pints) of gasoline per 100 miles driven. With this conclusion, we are satisfied with our analysis. Commands versus menus In this chapter, you have seen that Stata can operate either with menu choices and dialogs or with the Command window. As you become more familiar with Stata, you will find that the Command window is typically much faster for oft-used commands, whereas the menus and dialogs are faster when building up complex commands, such as those that create graphs. One of Stata’s great strengths is the consistency of its command syntax. Most of Stata’s commands share the following syntax, where square brackets mean that something is optional, and a varlist is a list of variables. prefix: command varlist if in weight , options Some general rules: • Most commands accept prefix commands that modify their behavior; see [U] 11.1.10 Prefix commands for details. One of the common prefix commands is by. • If an optional varlist is not specified, all the variables are used. • if and in restrict the observations on which the command is run. • options modify what the command does. • Each command’s syntax is found in the system help and the reference manuals. • Stata’s command syntax includes more than we have shown you here, but this introduction should get you started. For more information, see [U] 11 Language syntax and help language. We saw examples using all the pieces of this except for the in qualifier and the weight clause. The syntax for all commands can be found in the system help along with examples—see [GSW] 4 Getting help for more information. The consistent syntax makes it straightforward to learn new commands and to read others’ commands when examining an analysis. Here is an example of reading the syntax diagram that uses the summarize command from earlier in this chapter. The syntax diagram for summarize is typical: summarize varlist if in weight , options
  • 30. 22 [ GSW ] 1 Introducing Stata—sample session This means that command by itself is valid: summarize command followed by a varlist (variable list) is valid: summarize mpg summarize mpg weight command with if (with or without a varlist) is valid: summarize if mpg20 summarize mpg weight if mpg20 and so on. You can learn about summarize in [R] summarize, or select Help Stata Command... and enter summarize, or type help summarize in the Command window. Keeping track of your work It would have been useful if we had made a log of what we did so that we could conveniently look back at interesting results or track any changes that were made. You will learn to do this in [GSW] 16 Saving and printing results by using logs. Your logs will contain commands and their output—another reason to learn command syntax is so that you can remember what you have done. To make a log file that keeps track of everything appearing in the Results window, click on the Log button, which looks like a lab notebook, . Choose a place to store your log file, and give it a name, just as you would for any other document. The log file will save everything that appears in the Results window from the time you start a log file to the time you close it. Conclusion This chapter introduced you to Stata’s capabilities. You should now read and work through the rest of this manual. Once you are done here, you can read the User’s Guide.
  • 31. 2 The Stata user interface The windows This chapter introduces the core of Stata’s interface: its main windows, its toolbar, its menus, and its dialogs. The five main windows are the Review, Results, Command, Variables, and Properties windows. Except for the Results window, each window has its name in its title bar. These five windows are typically in use the whole time Stata is open. There are other, more specialized windows such as the Viewer, Data Editor, Variables Manager, Do-file Editor, Graph, and Graph Editor windows—these are discussed later in this manual. To open any window or to reveal a window hidden by other windows, select the window from the Window menu, or select the proper item from the toolbar. You can also use Ctrl+Tab to cycle through all open windows inside the main Stata window or Alt+Tab to cycle through all open windows (Stata and other) if you want to change windows from the keyboard. Many of Stata’s windows have functionality that can be accessed by clicking on the right mouse button (right-clicking) within the window. Right-clicking displays a contextual menu that, depending on the window, allows you to copy text, set the preferences for the window, or print the contents of the window. When you copy text or print, we recommend that you always right-click on the window rather than use the menu bar or toolbar so that you can be sure of where and what you are copying or printing. 23
  • 32. 24 [ GSW ] 2 The Stata user interface The toolbar This is the toolbar: The toolbar contains buttons that provide quick access to Stata’s more commonly used features. If you forget what a button does, hold the mouse pointer over the button for a moment, and a tooltip will appear with a description of that button. Buttons that include both an icon and an arrow display a menu if you click on the arrow. Here is an overview of the toolbar buttons and their functions: Open opens a Stata dataset. Click on the button to open a dataset with the Open dialog. Save saves the Stata dataset currently in memory to disk. Print displays a list of windows. Select a window name to print its contents. Log begins a new log or closes, suspends, or resumes the current log. See [GSW] 16 Saving and printing results by using logs for an explanation of log files. Viewer opens the Viewer or brings a Viewer to the front of all other windows. Click on the button to open a new Viewer. Click on the arrow to select a Viewer to bring to the front. See [GSW] 3 Using the Viewer for more information. Graph brings a Graph window to the front of all other windows. Click on the button to bring the Graph window to the front. Click on the arrow to select a Graph window to bring to the front. See The Graph button in [GSW] 14 Graphing data for more information. Do-file Editor opens the Do-file Editor or brings a Do-file Editor to the front of all other windows. Click on the button to open a new Do-file Editor. Click on the arrow to select a Do-file Editor to bring to the front. See [GSW] 13 Using the Do-file Editor—automating Stata for more information. Data Editor (Edit) opens the Data Editor or brings the Data Editor to the front of the other Stata windows. See [GSW] 6 Using the Data Editor for more information. Data Editor (Browse) opens the Data Editor in browse mode. See Browse mode in [GSW] 6 Using the Data Editor for more information. Variables Manager opens the Variables Manager. See [GSW] 7 Using the Variables Manager for more information. Clear more Condition tells Stata to continue when it has paused in the middle of long output. See [GSW] 10 Listing data and basic command syntax for more information. Break stops the current task in Stata. See [GSW] 10 Listing data and basic command syntax for more information.
  • 33. [ GSW ] 2 The Stata user interface 25 The Command window Commands are submitted to Stata from the Command window. The Command window supports basic text editing, copying and pasting, a command history, function-key mapping, and variable-name completion. From the Command window, pressing Page Up steps backward through the command history. Page Down steps forward through the command history. Tab auto-completes a partially typed variable name, when possible. See [U] 10 Keyboard use for more information about keyboard shortcuts for the Command window. The command history allows you to recall a previously submitted command, edit it if you wish, and then resubmit it. Commands submitted by Stata’s dialogs are also included in the command history, so you can recall and submit a command without having to open the dialog again. The Results window The Results window contains all the commands and their textual results you have entered during the Stata session. While you can scroll through the Results window to look at work you have done, it is much simpler to search within the Results window by using the find bar. By default, the find bar is hidden. You can expose it by selecting Edit Find. You can clear out the Results window at any time by right-clicking in the Results window and selecting Clear Results from the contextual menu. This action is not undoable. The Review window The Review window shows the history of commands that have been entered. It displays successful commands in black and unsuccessful commands, along with their error codes, in red. The toolbar has two tools for manipulating the contents of the Review window. Clicking on the Filter button, , in the Review window titlebar toggles the visibility of these tools. Text entered in the Filter commands here field will filter the commands appearing in the Review window. By default, the filter will ignore case and find any commands containing any of the words in the filter. Clicking on the wrench on the left will allow you to change this behavior. Clicking on the exclamation mark button toggles the hiding of commands that ran with an error. No commands are deleted by using these tools—all that is affected is their visibility. To enter a command from the Review window, you can • Click once on a past command to copy it to the Command window, replacing the contents of the Command window. • Double-click on a past command to resubmit it. Executing the command adds the command to the bottom of the Review window. Right-clicking on the Review window displays a menu from which you can select various actions: • Cut removes the selected commands from the Review window and places them on the Clipboard. • Copy copies the selected commands to the Clipboard. • Delete removes the selected commands from the Review window. • Select All selects all the commands in the Review window, including those before and after the commands currently displayed.
  • 34. 26 [ GSW ] 2 The Stata user interface • Clear All clears out all the commands from the Review window, including those before and after the commands currently displayed. • Do Selected submits all the selected commands and adds them to the bottom of the command history. Stata will attempt to run all the selected commands, even those containing errors, and will not stop even if a command causes an error. • Send to Do-file Editor places all the selected commands into a new Do-file Editor window. • Save All... brings up a Save Review Contents dialog, which allows you to save all the commands in the Review window, including those before and after the commands currently displayed, in a do-file. (See [GSW] 13 Using the Do-file Editor—automating Stata for more information on do-files.) • Save Selected... brings up a Save Review Contents dialog, which allows you to save the selected commands in the Review window in a do-file. • Font... brings up a Font dialog, allowing you to change the font used to display the Review window contents. The Variables window The Variables window shows the list of variables in the dataset, along with selected properties of the variables. By default, it shows all the variables and their variable labels. You can change what properties get displayed by right-clicking on the header of any column of the Variables window. Click once on a variable in the Variables window to select it. Multiple variables can be selected in the usual fashion, either by Ctrl-clicking on nonadjacent variables or by clicking on a variable and shift-clicking on a second variable to select all intervening variables. Double-clicking on a variable in the Variables window puts the selected variable at the insertion point in the Command window. The leftmost column of the Variables window is called the one-click paste column. You can also send variables to the Command window by hovering the mouse over the one-click paste column of the Variables window and clicking on the arrow that appears. The one-click paste column can be shown or hidden in the same fashion as the other columns in the Variables window. The Variables window supports filtering and reordering of variables. Clicking on the Filter button, , in the Variables window titlebar toggles the visibility of the filter. Text entered in the Filter variables here field will filter the variables appearing in the Variables window. The filter is applied to all visible columns and shows all variables that match the criteria in at least one column. By default, the filter will ignore case and show any variables for which at least one column contains any of the words in the filter. Clicking on the wrench on the left will allow you to change this behavior as well as add or remove additional columns containing information about the variables. You can reorder the variables in the Variables window by clicking on any column header. The first click sorts in ascending order, the second click sorts in descending order, and the third click puts the variables back in dataset order. Thus clicking on the Variable column header will make the Variables window display the variables in alphabetical order. Sorting in the Variables window is live, so if you change a property of a variable when the Variables window is sorted by that property, it will automatically move the variable to its proper location. Reordering the display order of the variables in the Variables window does not affect the order of the variables in the dataset itself.
  • 35. [ GSW ] 2 The Stata user interface 27 Right-clicking on a variable in the Variables window displays a menu from which you can select • Keep Only Selected Variables to keep just the selected variables in the dataset in memory. You will be asked for confirmation. This affects only the dataset in memory, not the dataset as saved on your disk. See [GSW] 12 Deleting variables and observations for more information. • Drop Selected Variables to drop, or eliminate, the selected variables from the dataset in memory. You will be asked for confirmation. Just as above, this affects only the dataset in memory, not the dataset as saved on your disk. See [GSW] 12 Deleting variables and observations for more information. • Copy Varlist to copy the selected variable names to the clipboard. • Select All to select all variables in the dataset that satisfy the filter conditions. If no filter has been specified, all variables will be selected. • Send Varlist to Command Window to send all selected variables to the Command window. • Font... to bring up a Font dialog, allowing you to change the font used to display the Variables window contents. Items from the contextual menu issue standard Stata commands, so working by right-clicking is just like working directly in the Command window. If you would like to hide the Variables window, click on its close button. To reveal a hidden Variables window, select Window Variables. The Properties window The Properties window displays variable and dataset properties. If a single variable is selected in the Variables window, its properties are displayed. If there are multiple variables selected in the Variables window, the Properties window will display properties that are common across all selected variables. Clicking the lock icon in the Properties window titlebar toggles the ability to alter properties of the selected variables. By default, changes are not allowed. Once the properties are unlocked, you can make any changes to variable or dataset properties you like. Each change you make will create a command that appears in the Results and Command windows, as well as in any command log, so the changes are reproducible. Using the Properties window is one of the simplest ways of managing notes, changing variable and value labels, and changing display formats. See [D] notes, [D] label, and [D] format. Clicking the arrow buttons next to the lock icon will select the previous or next variable shown in the Variables window, and that selection will be reflected in the Properties window. If you would like to hide the Properties window, click on its close box. If you would like to reveal a hidden Properties window, select Window Properties. You should also investigate the Variables Manager, explained in [GSW] 7 Using the Variables Manager, because it extends these capabilities and provides a good interface for managing variables. Menus and dialogs There are two ways by which you can tell Stata what you would like it to do: you can use menus and dialogs, or you can use the Command window. When you worked through the sample session in [GSW] 1 Introducing Stata—sample session, you saw that both ways have strengths. We will discuss the menus and dialogs here.
  • 36. 28 [ GSW ] 2 The Stata user interface Stata’s Data, Graphics, and Statistics menus provide point-and-click access to almost every command in Stata. As you will learn, Stata is fully programmable, and Stata users can even create their own dialogs and menus. The User menu provides a place for programmers to add their own menu items. Initially, it contains only some empty submenus. As an example, suppose you wish to perform a Poisson regression. You could type Stata’s poisson command, or you could select Statistics Count outcomes Poisson regression, which would display this dialog: This dialog provides access to all the functionality of Stata’s poisson command. Because the dependent and independent variables must be numeric, you will find that the combobox will display only numeric variables for choosing. The poisson command has many options that can be accessed by clicking on the multiple tabs across the top of the dialog. The first time you use the dialog for a command, it is a good idea to look at the contents of each tab so that you will know all the dialog’s capabilities. The dialogs for many commands have the by/if/in and Weights tabs. These provide access to Stata’s commands and qualifiers for controlling the estimation sample and dealing with weighted data. See [U] 11 Language syntax for more information on these features of Stata’s language. The dialogs for most estimation commands have the Maximization tab for setting the maximization options (see [R] maximize). For example, you can specify the maximum number of iterations for the optimizer.
  • 37. [ GSW ] 2 The Stata user interface 29 Most dialogs in Stata provide the same six buttons you see at the bottom of the poisson dialog above. OK issues a Stata command based on how you have filled out the fields in the dialog and then closes the dialog. Cancel closes the dialog without doing anything—just as clicking on the dialog’s close button does. Submit issues a command just like OK but leaves the dialog on the screen so that you can make changes and issue another command. This feature is handy when, for example, you are learning a new command or putting together a complicated graph. Help provides access to Stata’s help system. Clicking on this button will typically take you to the help file for the Stata command associated with the dialog. Clicking on it here would take you to the poisson help file. The help file will have tabs above groups of options to show which dialog tab contains which options. Reset resets the dialog to its default state. Each time you open a dialog, it will remember how you last filled it out. If you wish to reset its fields to their default values at any time, simply click on this button. Copy Command to Clipboard behaves much like the Submit button, but rather than issuing a command, it copies the command to the Clipboard. The command can then be pasted elsewhere (such as in the Do-file Editor). The command issued by a dialog is submitted just as if you had typed it by hand. You can see the command in the Results window and in the Review window after it executes. Looking carefully at the full command will help you learn Stata’s command syntax. In addition to being able to access the dialogs for Stata commands through Stata’s menus, you can also invoke them by using two other methods. You may know the name of a Stata command for which you want to see a dialog, but you might not remember how to navigate to that command in the menu system. Simply type db commandname to launch the dialog for commandname: . db poisson You will also find access to the dialog for a command in that command’s help file; see [GSW] 4 Getting help for more details. As you read this manual, we will present examples of Stata commands. You may type those examples as presented, but you should also experiment with submitting those commands by using their dialogs. Use the db command described above to quickly launch the dialog for any command that you see in this manual. The working directory If you look at the screenshot on page 23, you will notice the status bar at the base of the main Stata window that contains the name of the current working directory you set when you installed Stata. We will use the directory C:UsersmydirDocuments in our examples; your exact directory will differ. The current working directory is the folder where graphs and datasets will be saved when typing commands such as save filename. It does not affect the behavior of menu-driven file actions
  • 38. 30 [ GSW ] 2 The Stata user interface such as File Save or File Open.... Once you have started Stata, you can change the current working directory with the cd command. See [D] cd for full details. Stata always displays the name of the current working directory so that it is easy to tell where your graphs and datasets will be saved. Fine control of Stata’s windows When Stata is first launched, the Review, Results, Command, Variables, and Properties windows appear within the main Stata window. The Review, Variables, and Command windows are initially linked to one another and attached to the edges of the Stata window. They can be resized by dragging on their edges. They even have two more features: you can drag them by their titlebars to reposition them within the main window, and you can hide them as tabs when not in use. To do so, click on the pushpin icons in their titlebars. The Results window always occupies whatever space remains inside the main Stata window. All other windows that open up can be moved freely and independently of the Stata window. This default behavior is simple and familiar and needs little explanation. Try playing with the windows inside the main Stata window now. If you find that the window behavior is good, you can stop reading this section. If you find that you would like some extra customization or that you would simply like some technical explanation of added window behaviors, keep reading. Window types The Stata for Windows interface has two types of windows: docking and nondocking. The Review, Command, Variables, and Properties windows are docking windows. All other windows are nondocking. Docking windows have special characteristics that allow them to be used with other docking windows: they can be linked (sharing a window with a splitter dividing the windows) or tabbed (sharing a window with a tab for each docking window). They can be set to automatically hide when not needed. Nondocking windows have none of these special characteristics. Here is a brief comparison of the two types of windows: Docking windows • can be linked to other docking windows so that they share a window with a splitter dividing them; • can share one window with other docking windows with a tab for each; • can be dragged in and out of the main Stata window or other docking windows; • can be made to hide automatically when not in use; and • can be made to always appear in front of the main Stata window. Nondocking windows • are separate from the main Stata window (except for the Results window); • cannot be linked to other windows; • cannot be tabbed to another window; and • cannot be made to hide automatically when not in use. When Stata is first launched, the Review, Results, Command, Variables, and Properties windows appear within the main Stata window. The Review, Command, Variables, and Properties windows are docking windows and are initially both docked and linked to one another. The Results window is a nondocking window.
  • 39. [ GSW ] 2 The Stata user interface 31 Docking windows To allow docking windows to have extra features, select Edit Preferences General Preferences..., click on the Windowing tab, and check Allow dockable windows to be undocked. Until this is selected, the various windows will remain docked on the edges of the main Stata window. Docking windows can be dragged into (docked) and out of (undocked) the main Stata window or other docking windows. When you drag a docking window, a transparent blue box appears in place of the window. If you drag the box over the main Stata window or another docking window, docking guides appear (see figure 1). Dragging the box over a guide previews how and where the window will appear if you release the mouse button. Releasing the mouse button (dropping) when the box is over a guide (dropping) links or tabs the window as previewed, whereas releasing it when the box is not over a docking guide simply moves the window to that position. Dropping the box on one of the outer docking guides links the docking window to the window under the guide. For example, figure 1 shows how you would drag the Review window over the Variables window, at which point the docking guides appear. When you move the mouse over the bottom docking guide and release the mouse button, the Review window becomes linked to the Variables window and is displayed in the lower part of the window. When docking windows are linked, a divider (splitter) is inserted between them. The splitter allows the linked windows to be resized; increasing the size of one window decreases the size of the other. To prevent splitters from resizing linked windows, select Edit Preferences General Preferences..., click on the Windowing tab, and check Lock splitters. To undock a linked window, double-click on the window’s title bar or drag the window away from the other window. Figure 1: Linking two windows Dropping the box on the center docking guide (see figure 2) combines the docking window with the window under the guide. One docking window is created with a tab for each docked window at the bottom of the new window. Clicking on a tab displays its window. To undock a tabbed window, double-click on the window’s tab, or click and drag the window’s tab out of the docking window. The docking window containing the tabbed windows can also be linked to other docking windows. Figure 2: Docking two windows
  • 40. 32 [ GSW ] 2 The Stata user interface Auto Hide and pinning Docking windows support the Auto Hide feature, which automatically hides the docking windows when they are not in use. When this feature is enabled, a pushpin will appear in the title bar of all docked windows in the main Stata window. To enable Auto Hide for a docking window, click on the pushpin in the title bar (see figure 3) so that the pushpin is horizontal. Click on the pushpin again to disable Auto Hide; the pushpin will be vertical. After you enable Auto Hide for a docking window, the window is hidden when not in use and is displayed as a tab along an edge of the main Stata window. To show the window, move the mouse pointer over the tab. To hide the window again, move the mouse pointer outside the window. If the window has the focus (its title bar is highlighted), it will be hidden if you click on another window. Auto Hide works only on docking windows that are docked within the main Stata window. Figure 3: Enabling Auto Hide When you undock a docking window, you can move it in front of or behind other Stata windows, including the main Stata window. If you click on any part of the main Stata window, the main window will move to the front and obscure the undocked window. You can bring the undocked window back to the front by selecting it from the Window menu. Or you can just make undocked windows always appear in front of the main Stata window (float) by selecting Edit Preferences General Preferences..., clicking on the Windowing tab, and checking Float dialogs and undocked-dockable windows. In addition to dragging the window, you can dock or undock a docking window by double-clicking on its title bar. You can double-click on the title bar again to move the window back to its previously docked or undocked location. If you enable Auto Hide for the Review window in its default docked location, it will obscure any text at the beginning of the Command window when it is displayed. To avoid this problem, dock this window at the right edge of the main Stata window before enabling Auto Hide. Nondocking windows Nondocking windows include the Graph window, Data Editor, Do-file Editor, Viewers, and dialogs. These windows are always independent of the main Stata window. The Results window, because of its status as the primary window of Stata, must remain inside the main Stata window.
  • 41. 3 Using the Viewer The Viewer’s purpose The Viewer is a versatile tool in Stata. It will be the first place you can turn for help within Stata, but it is far more than just a help system. You can also use the Viewer to add, delete, and manage third-party extensions to Stata that are known as user-written programs; to view and print Stata logs from both your current and your previous Stata sessions; to view and print any other Stata-formatted (SMCL) or plain-text file; and even to launch your web browser to follow hyperlinks. This chapter focuses on the general use of the Viewer, its buttons, and a brief summary of the commands that the Viewer understands. There is more information about using the Viewer to find help in [GSW] 4 Getting help and for installing user-written commands in [GSW] 19 Updating and extending Stata—Internet functionality. To open a new Viewer window, you may either click on the Viewer button, , or select Window Viewer New Viewer. A Viewer opened by these means provides links that allow you to perform several tasks. 33
  • 42. 34 [ GSW ] 3 Using the Viewer Viewer buttons The toolbar of the Viewer has multiple buttons, a command box, and a search box. Back goes back one step in your viewing trail. Forward goes forward one step in your viewing trail, as- suming you backtracked. Refresh refreshes the Viewer, in case you are viewing some- thing that has changed since you opened the Viewer. Print prints the contents of the Viewer. Find opens the find bar at the bottom of the Viewer (see below). Search Chooses the scope of help searches in the Viewer. The Find bar is used to find text within the current Viewer. To reveal the Find bar at the bottom of the window, click on the Find button (see above): The Find bar has its own buttons, fields, and checkboxes. Close closes the Find bar. Find is the field for entering the search text you would like to find. You can change the search options by using the checkboxes. Next jumps to the next instance of the search text; it au- tomatically wraps past the end of the Viewer document if there are no further instances of the search text. Previous jumps to the previous instance of the search text; it automatically wraps past the start of the Viewer document if there are no previous instances of the search text. Highlight All highlights other instances of the search text (in yellow, by default) when this box is checked. If unchecked, only the current instance of the search text is highlighted (in black, by default). By default, this box is checked. Match Case, when checked, considers uppercase and low- ercase letters to be different. When this box is checked, searching for This would not find this. If unchecked, up- percase and lowercase letters are considered the same, so searching for This would find this. By default, this box is unchecked.
  • 43. [ GSW ] 3 Using the Viewer 35 Viewer’s function The Viewer is similar to a web browser. It has links (shown in blue text) that you can click on to see related help topics and to install and manage third-party software. When you move the mouse pointer over a link, the status bar at the bottom of the Viewer shows the action associated with that link. If the action of a link is help logistic, clicking on that link will show the help file for the logistic command in the Viewer. Middle-clicking on a link in a Viewer window (if you do not have a three-button mouse, then Shift+clicking) will open the link in a new Viewer window. Ctrl+clicking will open the link in a new tab in the current Viewer window. You can open a new Viewer by selecting Window Viewer New Viewer or by clicking on the Viewer button on the toolbar. Entering a help command from the Command window will also open a new Viewer. To bring a Viewer to the front of all other Viewers, select Window Viewer and choose a Viewer from the list there. Selecting Close All Viewers closes all open Viewer windows. Viewing local text files, including SMCL files In addition to viewing built-in Stata help files, you can use the Viewer to view Stata Markup and Control Language (SMCL) files such as those typically produced when logging your work (see [GSW] 16 Saving and printing results by using logs) as well as plain-text files. To open a file and view its contents, simply select File View..., and you will be presented with a dialog: You may either type in the name of the file that you wish to view and click on OK, or you may click on the Browse... button to open a standard file dialog that allows you to navigate to the file. If you currently have a log file open, you may view the log file in the Viewer. This method has one advantage over scrolling back in the Results window: what you view stays fixed even as output is added to the Results window. If you wish to view a current log file, select File Log View..., and the usual dialog will appear but with the path and filename of the current log already in the field. Simply click on OK, and the log will appear in the Viewer. See [GSW] 16 Saving and printing results by using logs for more details. Viewing remote files over the Internet If you want to look at a remote file over the Internet, the process is similar to viewing a local file, only instead of using the Browse... button, you type the URL of the file that you want to see, such as http://www.stata.com/man/readme.smcl. You should use the Viewer only to view text or SMCL files. If you enter the URL of, say, an arbitrary webpage, you will see the HTML source of the page instead of the usual browser rendering.
  • 44. 36 [ GSW ] 3 Using the Viewer Navigating within the Viewer In addition to using the scrollbar to navigate the Viewer window, you also can use the up and down arrow keys and Page Up and Page Down keys to do the same. Pressing the up or down arrow key scrolls the window a line at a time. Pressing the Page Up or Page Down key scrolls the window a screen at a time. Printing To print the contents of the Viewer, right-click on the window and select Print.... You may also select File Print Viewer name or click on the arrow of the Print toolbar button to select from a menu of open windows to print. Tabs in the Viewer The Viewer window can have multiple tabs. You may view different files or different views of the same file in different tabs. Clicking on the Open New Tab button, , will open a new tab in the current Viewer window. You can change the order of the tabs within a Viewer by dragging the tabs along the tab bar within the window. If you drag a tab and drop it within the body of the same Viewer window, a menu will appear. If you select New Horizontal Tab Group, the Viewer window will be split horizontally. This is useful for having two views of the same file at different places in the file. Similarly, if you select New Vertical Tab Group, the Viewer window will be split vertically. This is useful for comparing two similar files side by side. Once you have created a horizontal or vertical tab group, if you drop a tab inside a group, you will get the choice of creating a similar new group or moving the tab to the selected group. Right-clicking on the Viewer window Right-clicking on the Viewer window displays a contextual menu that offers these options: • Select All to select all text in the Viewer. • Preferences... to edit the preferences for the Viewer window. • Font... to change the font for the window. • Print... to print the contents of the Viewer window. Searching for help in the Viewer The search box in the Viewer can be used to search documentation. Click on the magnifying glass; choose Search all, Search documentation and FAQs, or Search net resources; and then type a word or phrase in the search box and press Enter. For more extensive information about using the Viewer for help, see [GSW] 4 Getting help. Commands in the Viewer Everything that can be done in the Viewer by clicking on links and buttons can also be done by typing commands in the command box at the top of the window or on the Stata command line. Some tasks that can be performed in the Viewer are
  • 45. [ GSW ] 3 Using the Viewer 37 • obtaining help (see [GSW] 4 Getting help): Type contents to view the contents of Stata’s help system. Type commandname to view the help file for a Stata command. • searching (see [GSW] 4 Getting help): Type search keyword to search documentation, FAQs, and net resources for a topic. Type search keyword, local to search only documentation and FAQs for a topic. Type search keyword, net to search only net resources for a topic. • finding and installing User-written programs (see [GSW] 4 Getting help and [GSW] 19 Updating and extending Stata—Internet functionality): Type net from http://www.stata.com/ to find and install Stata Journal, Stata Technical Bulletin, and user-written programs from the Internet. Type ado to review user-written programs you have installed. Type ado uninstall to uninstall user-written programs you have installed on your computer. • viewing files in the Viewer: Type view filename.smcl to view SMCL files. Type view filename.txt to view text files. Type view filename.log to view text log files. • viewing files in the Results window: Type type filename.smcl in the Command window to view SMCL files in the Results window. Type type filename.txt in the Command window to view text files in the Results window. Type type filename.log in the Command window to view text log files in the Results window. • launching your browser to view an HTML file: Type browse URL to launch your browser. • keeping informed: Type news to see the latest news from http://www.stata.com. Using the Viewer from the Command window Typing help commandname in the Command window will bring up a new Viewer showing the requested help.
  • 46. 4 Getting help System help Stata’s help system provides a wealth of information to help you learn and use Stata. To find out which Stata command will perform the statistical or data management task you would like to do, you should generally follow these steps: 1. Select Help Search..., choose Search all, and enter the topic or keywords. This search will open a new Viewer window containing information about Stata commands, references to articles in the Stata Journal, links to Frequently Asked Questions (FAQs) on Stata’s website, links to videos on Stata’s YouTube channel, links to selected external websites, and links to user-written commands. 2. Read through the results. If you find a useful command, click on the link to the appropriate command name to open its help file. 3. Read the help file for the command you chose. 4. If you want more in-depth help, click on the link from the name of the command to the PDF documentation, read it, then come back to Stata. 5. If the first help file you went to is not what you wanted, either click on the Also See button and choose a link to related help files or click on the Back button to go back to the previous document and go from there to other help files. 6. With the help file open, click on the Command window and enter the command, or click on the Dialog button and choose a link to open a dialog for the command. 7. If, at any time, you want to begin again with a new search, enter the new search terms in the search box of the Viewer window. 8. If you select Search documentation and FAQs, Stata searches its keyword database for official Stata commands, Stata Journal and STB articles and software, FAQs, and videos. If you select Search net resources, Stata searches for user-written commands, whether they are from the Stata Journal, the STB, or elsewhere; see [GSW] 19 Updating and extending Stata—Internet functionality for more information. Let’s illustrate the help system with an example. You will get the most benefit from the example if you work along at your computer. Suppose that we have been given a dataset about antique cars and that we need to know what it contains. Though we still have a vague notion of having seen something like this while working through the example session in [GSW] 1 Introducing Stata—sample session, we do not remember the proper command. Start by typing sysuse auto, clear in the Command window to bring the dataset into memory. (See [GSW] 5 Opening and saving Stata datasets for information on the clear option.) Following the above approach, 1. select Help Search.... 2. check that the Search all radio button is selected. 3. type dataset contents into the search box and click on OK or press Enter. Before we press Enter, the window should look like 38
  • 47. [ GSW ] 4 Getting help 39 4. Stata will now search for “dataset contents” among the Stata commands, the reference manuals, the Stata Journal, the FAQs on Stata’s website, and user-written commands. Here is the result: 5. upon seeing the results of the search, we see two commands that look promising: codebook and describe. Because we are interested in the contents of the dataset, we decide to check out the codebook command. The [D] means that we could look up the codebook command in the Data Management Reference Manual. The blue codebook link in (help codebook) means that there is a system help file for the codebook command. This is what we are interested in right now.
  • 48. 40 [ GSW ] 4 Getting help 6. click on the blue codebook link. Links can take you to a variety of resources, such as help for Stata commands, dialogs, and even webpages. Here the link goes to the help file for the codebook command. 7. what is displayed is typical for help for a Stata command. Help files for Stata commands contain, from top to bottom, these features: a. The quick access toolbar with three buttons: i. The Dialog button shows links to any dialogs associated with the command. ii. The Also See button shows links to related PDF documentation and help files. iii. The Jump To button shows links to other sections within the current help file. b. The very first link in the Title section is a link to the manual entry for the command in the PDF documentation. Clicking on the link will open your PDF viewer and show you the complete documentation for the command—in this case, codebook. c. The command’s syntax, that is, rules for constructing a command that Stata will correctly interpret. The square brackets here indicate that all the arguments to codebook are optional but that if we wanted to specify them, we could use a varlist, an if qualifier, or an in qualifier, along with some options. (Options vary greatly from command to command.) The options are listed directly under the command and are explained in some detail later in the help file. You will learn more about command syntax in [GSW] 10 Listing data and basic command syntax. d. A description of the command. Because “codebook” is the name for big binders containing hard copy describing each of the elements of a dataset, the description for the codebook command is justifiably terse. e. The options that can be used with this command. These are explained in much greater detail than in the listing of the possible options after the syntax. Here, for example, we can see that the mv option can look to see if there is a pattern in the missing values—something important for data cleaning and imputation.
  • 49. [ GSW ] 4 Getting help 41 f. Examples of command usage. The codebook examples are real examples that step through using the command on a dataset either shipped with Stata or loadable within Stata from the Internet. g. The information the command stores in the returned results. These results are used primarily by programmers. For now, either click on Jump To and choose Examples from the drop-down menu or scroll down to the examples. It is worth going through the examples as given in the help file. Here is a screenshot of the top of the examples: Searching help Search is designed to help you find information about statistics, graphics, data management, and programming features in Stata, either as part of the official release or as user-written commands. When entering topics for the search, use appropriate terms from statistics, etc. For example, you could enter Mann-Whitney. Multiple topic words are allowed, for example, regression residuals. When you are using Search, use proper English and proper statistical terminology. If you already know the name of the Stata command and want to go directly to its help file, select Help Stata Command... and type the command name. You can also type the command name in the Search field at the top of the Viewer and press Enter. Help distinguishes between topics and Stata commands because some names of Stata commands are also general topic names. For example, logistic is a Stata command. If you choose Stata Command... and type logistic, you will go right to the help file for the command. But if you choose Search... and type logistic, you will get search results listing the many Stata commands that relate to logistic regression.
  • 50. 42 [ GSW ] 4 Getting help Remember that you can search for help from within a Viewer window by typing a command in the command box of the Viewer or by clicking the magnifying glass button to the left of the search box, selecting the scope of your search, typing the search criteria in the search box, and pressing Enter. Help and search commands As you might expect, the help system is accessible from the Command window. This feature is especially convenient when you need help on a particular Stata command. Here is a short listing of the various commands you can use: • Typing help commandname is equivalent to selecting Help Stata Command... and typing commandname. The help file for the command appears in a new Viewer window. • Typing search topic in the Command window produces the same output as selecting Help Search..., choosing Search all, and typing topic. The output appears in a new Viewer window. • Typing search topic, local in the Command window produces the same output as selecting Help Search..., choosing Search documentation and FAQs, and typing topic. The output appears in the Results window instead of a Viewer. • Typing search topic, net in the Command window produces the same output as selecting Help Search..., choosing Search net resources, and typing topic. The output appears in the Results window instead of a Viewer. See [U] 4 Stata’s help and search facilities and [U] 4.8 search: All the details in the User’s Guide for more information about these command-language versions of the help system. The search command, in particular, has a few capabilities (such as author searches) that we have not demonstrated here. The Stata reference manuals and User’s Guide All the Stata reference manuals come as PDF files and are included with the software. The manuals themselves have many cross-references in the form of clickable links, so you can easily read the documentation in a nonlinear way. Many of the links in the help files point to the PDF manuals that came with Stata. It is worth clicking on these links to read the extensive information found in the manuals. The Stata help system, though extensive, contains only a fraction of the information found in the manuals. The Stata reference manuals are each arranged like an encyclopedia, alphabetically, and each has its own index. The User’s Guide also has an index. The Glossary and Index contains a combined index for the User’s Guide and all the reference manuals. This combined index is a good place to start when you are looking for information about a command. Entries have names like collapse, egen, and summarize, which are generally themselves Stata commands. Notations such as [R] ci, [R] regress, and [R] ttest in the Search results and help files are references to the Base Reference Manual. You may also see things like [P] #delimit, which is a reference to the Programming Reference Manual, and [U] 9 The Break key, which is a reference to the User’s Guide. For a complete list of manuals and their shorthand notations, see Cross-referencing the documentation, which immediately follows the table of contents in this manual. For advice on how to use the reference manuals, see [GSW] 18 Learning more about Stata, or see [U] 1.2 The User’s Guide and the Reference manuals.