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 on April 23, 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   Max.Livingston@ny.frb.org
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 13:19:18 -0500

Thanks!

I never realized that the extended macro functions could be used without 
directly assigning their output to a macro. Interesting...

Max


Max Livingston
Research Analyst
Microeconomic Studies
Research and Statistics Group
Federal Reserve Bank of New York
(212) 720-7894



From:   Nick Cox <njcoxstata@gmail.com>
To:     statalist@hsphsun2.harvard.edu, 
Date:   12/24/2012 12:01 PM
Subject:        Re: st: Is there a way to tell if a local macro contains a 
particular value
Sent by:        owner-statalist@hsphsun2.harvard.edu



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/






This e-mail message, including attachments, is for the sole use of the intended recipient(s) and may contain confidential or proprietary information.  If you are not the intended recipient, immediately contact the sender by reply e-mail and destroy all copies of the original message.
*
*   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