Bookmark and Share

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]

Re: st: Is there a way to tell if a local macro contains a particular value


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Is there a way to tell if a local macro contains a particular value
Date   Mon, 24 Dec 2012 16:53:28 +0000

Yes. See -help macrolists-.

. sysuse auto
(1978 Automobile Data)

. unab m_all : m*

. local make "make"

. local in : list make in m_all

. di  `: list make in m_all'
1

. mac li
<other stuff>
_in:            1
_make:          make
_m_all:         make mpg

In your case

foreach v of var var1-var6 {
        if `: list v in myvars'  di "`v' is in the list"
        else di "`v' is not"
}

Nick

On Mon, Dec 24, 2012 at 4:34 PM,  <[email protected]> wrote:

> Say I have a local macro with a list of variable names: local myvars var1
> var3 var5.
>
> Now say I'm iterating over all my variables (var1-var6), and want to do
> something if the variable is in `myvars.' Is there a simple way to
> determine this?
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index