Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Macro question


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Macro question
Date   Tue, 15 Mar 2005 15:39:41 -0000

foreach  v of local varlist { 
	local list `" `list' "`v'", "'
}

adds a comma too many, so I guess
you need something like this 

tokenize "`varlist'" 
local nv : word count `varlist' 
forval i = 1/`=`nv' - 1' { 
	local list `" `list' "``i''", "' 
} 
local list `" `list' "``nv''" "' 


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

Fred Wolfe
 
> Can anyone help with this macro question:
> 
> In a program syntax statement
> 
> syntax, vlist(varlist)
> 
> I create a local macro vlist which end up containg:
> 
> di"`vlist'"
> 
> plaghaq_disability plaghaq2 plagpas
> 
> I want to use the contents of that macro in an inlist() 
> function like this:
> 
> if inlist(parm,"plaghaq_disability", "plaghaq2", "plagpas")
> 
> So I need to transform
> 
> this list:
> plaghaq_disability plaghaq2 plagpas
> 
> into this list:
> 
> "plaghaq_disability", "plaghaq2", "plagpas" in a macro. I am having 
> problems adding the quotation marks.
> 
> Can anyone tell me how to do this?

*
*   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