Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: variables into a macro


From   n j cox <n.j.cox@durham.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: variables into a macro
Date   Sun, 04 Nov 2007 17:37:26 +0000

Everyone's right.

Another way is through -describe, varlist-.

Maarten touched on the fact that multiple versions
of -ds- exist. The history is roughly as follows:

-ds- was originally an official Stata command.
It remains an official command. As of Stata 9,
it went undocumented. That is Stataspeak
for "undocumented in the manual, but documented
on-line". (Commands that are not documented
at all are thus better called not documented or
non-documented.)

In STB-56 and STB-60 a user-written -ds2-
was published. As Maarten says, a user-written
-ds3- is also available from SSC. As the author
of both, my line is that -ds3- is just a bit
too complicated. What I thought were the best
ideas in either were taken over by StataCorp
for -ds- within Stata 8. Thus I am not developing
-ds3-.

A separate -ds5- on SSC is not more advanced than
any, but was for Stata 5.

Nick
n.j.cox@durham.ac.uk

John Wallace
--------------------------------------------------------------------------------
I'd like to write a routine for a do-file that loads all the variable
names in the current dataset into a macro for further manipulation
(selection of subsets based on patterns in their names).

Philipp Rehm
--------------------------------------------------------------------------------
ds _all
di "`r(varlist)'"

But you may want to select variables into a macro, based on the patterns
of their name (or other characteristics). Again, -ds- is very helpful here.

Peter J. Burke
--------------------------------------------------------------------------------
-unab var: _all-

Maarten Buis
--------------------------------------------------------------------------------
An extended version is -ds3- by Nick Cox downloadable from -ssc-

Austin Nichols
--------------------------------------------------------------------------------
In addition to
unab v: _all
di "`v'"
ds
di r(varlist)

another way is available via -syntax- e.g.

sysuse auto, clear
syntax [varlist]
di "`varlist'"

which is a handy trick in a do-file in addition to being invaluable in
-program-s since you can supply a varlist to your do-file, or (by
default) let it operate on all variables.


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index