Stata
Products Purchase Support Company
Search
   >> Home >> Resources & support >> FAQs >> Shortcuts to refer multiple variables

How can I list, drop, and keep a consecutive set of variables without typing the names individually?

Title   Shortcuts to refer multiple variables
Author Paul Lin, StataCorp
Date March 1997

Understand that whenever Stata wants a varlist it can be a list of variables, such as

        . list length turn 

or it can be all variables starting with a certain prefix

        . list rep*

(meaning all variables named "rep" followed by something), or it can be a range of variables

        . list mpg-weight

(meaning all variables mpg through weight in the order that the variables are recorded in the dataset).

You can even combine all three syntaxes:

        . list length turn rep* mpg-weight

The only thing Stata is missing is an easy way to specify variables v1, v2, .... When the names are in common, the variables are numbered sequentially, but they are not stored sequentially. For instance, pretend that the order of the variables in the dataset is

        1.  v1
        2.  alpha
        3.  v3
        4.  beta
        5.  v4
        6.  v2
        7.  gamma

Then typing

        . list v1-v4

is equivalent to typing

        . list v1 alpha v3 beta v4

and is not equivalent to typing

        . list v1 v2 v3 v4

Here you want to consider reordering the variables in your dataset. aorder will put the variables in alphabetical order (and does mostly smart things with numeric suffixes). In the above example, if I type

        . aorder

the resulting order is

        1.  alpha
        2.  beta
        3.  gamma
        4.  v1
        5.  v2
        6.  v3
        7.  v4

aorder is smart enough to know that v10 comes after v9 and not between v1 and v2, which pure alphabetical order would specify. For online help, type help aorder in Stata, or see [D] order.

FAQs
What's new?
Statistics
Data management
Graphics
Programming Stata
Mata
Resources
Internet capabilities
Stata for Windows
Stata for Unix
Stata for Macintosh
Technical support
Resources & support
FAQs
Technical support
NetCourses
Short courses
Users Group meetings
Statalist
Links
Software updates
Software archives
Customer service
Manuals & supplements
Stata Journal
STB
Stata News
Stata Automation
Plugins

Site overview
Products
Resources & support
Company
Site index

© Copyright 1996–2008 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index