Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
AW: st: Tokenize local varlist
From
"Martin Weiss" <[email protected]>
To
<[email protected]>
Subject
AW: st: Tokenize local varlist
Date
Tue, 13 Jul 2010 09:01:52 +0200
<>
" Use -display- to check the contents of your locals. "
Or indeed use -macro dir- to see them all at once...
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Eric Booth
Gesendet: Dienstag, 13. Juli 2010 05:47
An: <[email protected]>
Betreff: Re: st: Tokenize local varlist
<>
Use -display- to check the contents of your locals. Also, notice that local
doesn't take a varlist, it takes an expression; so, local doesn't expand the
varlist for your line "local tvars prefix_*" :
*******!
sysuse auto, clear
rename mpg prefix_mpg
rename price prefix_price
rename weight prefix_weight
rename foreign prefix_foreign
*****
local tvars prefix_*
di "`tvars'" // doesn't work
*****
ds prefix_*
local tvars `r(varlist)'
di "`tvars'"
token `tvars'
di "`1'"
local regressand `1'
mac shift
local regressors `*'
di "`regressors'"
**
regress `regressand' `regressors'
di "`e(cmdline)'"
*******!
~ Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754
On Jul 12, 2010, at 10:32 PM, Dani Tilley wrote:
> local tvars prefix_*
> token `tvars'
> local regressand `1'
> mac shift
> local regressors `*'
>
> So I try to assign all the variables that begin with "prefix_" to local
varlist
> tvars, and then I tokenize tvars and attempt to assign the first variable
to
> local regressand and the rest to regressors. However, when I -browse `1'-
after
> tokenizing tvars I get all the variables beginning with prefix_ (i.e. all
> tvars), and after I -ma s- and -browse `*'- I get all the variables in my
data
> set.
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/