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]

st: RE: can I use a global macro as a trigger?


From   "Radwin, David" <dradwin@rti.org>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: can I use a global macro as a trigger?
Date   Wed, 29 May 2013 18:26:33 -0400

Melanie,

Yes, you just need quotation marks around the global macros, like this:



global type standard

if "${type}"=="standard" {
	display as result "Standard scenario."
	}

else if "${type}"=="special" {
	display as result "Special scenario."
	}


This is legal usage for the programmer's -if-, also known as the -if-
command. See -help ifcmd- for details.

David
--
David Radwin
Senior Research Associate
Education Studies Division
RTI International
2150 Shattuck Ave., Suite 800
Berkeley, CA 94704
Phone: 510-665-8274

www.rti.org


> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-
> statalist@hsphsun2.harvard.edu] On Behalf Of Melanie Leis
> Sent: Wednesday, May 29, 2013 3:02 PM
> To: statalist
> Subject: st: can I use a global macro as a trigger?
> 
> Hello all,
> 
> I have a .do file for which I need to run different sections depending
> on whether what I'm doing is a standard or a special scenario.
> Ideally, I would like to use a macro to trigger this, so that at the
> beginning of my .do file I just have to specify my global type as
> standard or special, and then have it automatically know which part of
> the code to run.  The idea of what I want to do is something like:
> 
> global type standard
> 
> if ${type}=="standard" {
> 
> "run code"
> 
> }
> else if ${type}=="special"{
> 
> "run other code"
> 
> }
> 
> I understand that the if command does not work like this (it's looking
> for variables), but is there a way that I could use this global
> command at the beginning of my .do file to indicate which part of the
> code to run?
> 
> Thanks!
> 
> Melanie

*
*   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