Title | Shortcuts to refer multiple variables | |
Author | Paul Lin, StataCorp |
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. order, sequential will put the variables in alphabetical order (and does mostly smart things with numeric suffixes). In the above example, if I type
. order *, sequential
the resulting order is
1. alpha 2. beta 3. gamma 4. v1 5. v2 6. v3 7. v4
order, sequential 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 order in Stata, or see [D] order.
Learn
Free webinars
NetCourses
Classroom and web training
Organizational training
Video tutorials
Third-party courses
Web resources
Teaching with Stata
© Copyright 1996–2024 StataCorp LLC. All rights reserved.
×
We use cookies to ensure that we give you the best experience on our website—to enhance site navigation, to analyze usage, and to assist in our marketing efforts. By continuing to use our site, you consent to the storing of cookies on your device and agree to delivery of content, including web fonts and JavaScript, from third party web services.
Cookie Settings
Last updated: 16 November 2022
StataCorp LLC (StataCorp) strives to provide our users with exceptional products and services. To do so, we must collect personal information from you. This information is necessary to conduct business with our existing and potential customers. We collect and use this information only where we may legally do so. This policy explains what personal information we collect, how we use it, and what rights you have to that information.
These cookies are essential for our website to function and do not store any personally identifiable information. These cookies cannot be disabled.
This website uses cookies to provide you with a better user experience. A cookie is a small piece of data our website stores on a site visitor's hard drive and accesses each time you visit so we can improve your access to our site, better understand how you use our site, and serve you content that may be of interest to you. For instance, we store a cookie when you log in to our shopping cart so that we can maintain your shopping cart should you not complete checkout. These cookies do not directly store your personal information, but they do support the ability to uniquely identify your internet browser and device.
Please note: Clearing your browser cookies at any time will undo preferences saved here. The option selected here will apply only to the device you are currently using.