Statalist


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

Re: st: Re:Obtaining varlist from other dataset


From   Keith Dear <keith.dear@anu.edu.au>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Re:Obtaining varlist from other dataset
Date   Sat, 02 Feb 2008 19:26:18 +1100

That's one of the glories of Stata - there's ALWAYS a better way :)
Cheers Phil,
Keith

At 06:59 PM 2/02/2008, you wrote:
Another approach:

local myvars `r(varlist)'

also works. The left-single-quote, right-single-quote construct expands the
macro (to yield the list of variable names) and then copies those names to
myvars.

This may have advantages over Keith's solution, as evaluation and assignment (ie
using "=") will break down if the variable list, and hence the string length of
the list, gets beyond 244. This limitation does not apply to expansion and
copying.

Phil








Quoting "P. Wilner Jeanty" <pwjeanty@gmail.com>:

> On Feb 2, 2008 12:57 AM, Keith Dear <keith.dear@anu.edu.au> wrote:
> > David,
> > Wilner is right, the varlist option does solve your problem. But the
> statement:
> > . local myvars r(varlist)
> > merely assigns the string "r(varlist)" to the macro, which therefore
> > contains only one word.
> > You can verify this with
> > . display "`myvars'"
> > r(varlist)
> >
> > You can get what you need like this:
> > . describe using my_file, varlist
> > . local myvars=r(varlist) // "=" inserted
> > . display "`myvars'"
> > x1 x2 x3 x4
> >
> > The "=" has the effect of *evaluating* r(varlist), and assigning the
> > result to myvars.
> > Keith
>
> David's problem is indeed solved. Not only can he put all the
> variables in a macro, he can also put them in separate macros. As
> Keith clarified, the "=" sign solved the problem of extended macro
> function manipulation.
> --
> P. Wilner Jeanty, Post-doctoral researcher
> Dept. of Agricultural, Environmental, and Development Economics
> The Ohio State University
> 2120 Fyffe Road
> Columbus, Ohio 43210
> (614) 292-6382 (Office)
> *
> * 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/
>


--
Philip Ryan
Professor
Discipline of Public Health

Director, Data Management and Analysis Centre
Associate Dean (IT)
Faculty of Health Sciences

University of Adelaide
5005 South Australia
AUSTRALIA
CRICOS Provider Number 00123M
-----------------------------------------------------------
This email message is intended only for the addressee(s)
and contains information that may be confidential and/or
copyright. If you are not the intended recipient please
notify the sender by reply email and immediately delete
this email. Use, disclosure or reproduction of this email
by anyone other than the intended recipient(s) is strictly
prohibited. No representation is made that this email or
any attachments are free of viruses. Virus scanning is
recommended and is the responsibility of the recipient.
*
* 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/
*
*   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