Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <n.j.cox@durham.ac.uk> |
To | "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu> |
Subject | RE: st: check if a macro contains a value |
Date | Mon, 16 May 2011 16:57:52 +0100 |
I don't see any need for special tricks here. Something like if strpos("$steps", "1") { ... } will pick up whether 1 was included in the global. Nick n.j.cox@durham.ac.uk Maarten Buis On Mon, May 16, 2011 at 4:29 PM, Dimitri Szerman <dimitrijoe@gmail.com> 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 ) * * 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/