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: check if a macro contains a value


From   Maarten Buis <[email protected]>
To   [email protected]
Subject   Re: st: check if a macro contains a value
Date   Mon, 16 May 2011 17:03:12 +0200

On Mon, May 16, 2011 at 4:29 PM, Dimitri Szerman <[email protected]> wrote:
> I'm running a big do-file which contains several steps. I would like
> to create a macro (a global, I suppose) which contains the steps which
> are to be run.

This sounds like a job for extended macro functions. Below is an
example that I think does what you want. To learn more about this,
type in Stata -help macro-, click on the link for extended macro
functions. In this case I used the "macro extended functions for
manipulating lists".

*---------------- begin example ------------
global steps "1 2 4"

// step 1
local one "1"
if `: list one in global(steps)' {
	di "step 1"
}


// step 2
local two "2"
if `: list two in global(steps)' {
	di "step 2"
}


// step 3
local three "3"
if `: list three in global(steps)' {
	di "step 3"
}


// step 4
local four "4"
if `: list four in global(steps)' {
	di "step 4"
}
*------------------ end example --------------------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany


http://www.maartenbuis.nl
--------------------------
*
*   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/


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