10 Listing data and basic command syntax
Command syntax
This chapter gives a basic lesson on Stata’s command syntax while showing how to control the
appearance of a data list.
As we have seen throughout this manual, you have a choice between using menus and dialogs
and using the Command window. Although many find the menus more natural and the Command
window baffling at first, some practice makes working with the Command window often much faster
than using menus and dialogs. The Command window can become a faster way of working because
of the clean and regular syntax of Stata commands. We will cover enough to get you started; help
language has more information and examples, and [U] 11 Language syntax has all the details.
The syntax for the list command can be seen by typing help list:
list
varlist
if
in
, options
Here is how to read this syntax:
• Anything inside square brackets is optional. For the list command,
a. varlist is optional. A varlist is a list of variable names.
b. if is optional. The if qualifier restricts the command to run only on those observations for
which the qualifier is true. We saw examples of this in [GSW] 6 Using the Data Editor.
c. in is optional. The in qualifier restricts the command to run on particular observation
numbers.
d. , and options are optional. options are separated from the rest of the command by a
comma.
• Optional pieces do not preclude one another unless explicitly stated. For the list command,
it is possible to use a varlist with if and in.
• If a part of a word is underlined, the underlined part is the minimum abbreviation. Any
abbreviation at least this long is acceptable.
a. The l in list is underlined, so l, li, and lis are all equivalent to list.
• Anything not inside square brackets is required. For the list command, only the command
itself is required.
Keeping these rules in mind, let’s investigate how list behaves when called with different arguments.
We will be using the dataset afewcarslab.dta from the end of the previous chapter.
list with a variable list
Variable lists (or varlists) can be specified in a variety of ways, all designed to save typing and
encourage good variable names.
• The varlist is optional for list. This means that if no variables are specified, it is equivalent to
specifying all variables. Another way to think of it is that the default behavior of the command
is to run on all variables unless restricted by a varlist.
• You can list a subset of variables explicitly, as in list make mpg price.
• There are also many shorthand notations:
m* means all variables starting with m.
price-weight means all variables from price through weight in the dataset order.
ma?e means all variables starting with ma, followed by any character, and ending in e.
1