Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[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 <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
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,  <Max.Livingston@ny.frb.org> 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index