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]

st: RE: Irritating if...else question for mata vs. stata


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Irritating if...else question for mata vs. stata
Date   Sun, 6 Jun 2010 19:27:24 +0100

You need not apologise that (you think) your question is irritating. 

No -else- is needed in Mata with multiple blocks. 

Here's a dopey demo to run. 

mata : 

void testif() { 
	if (42 > 0) { 
		"42 is positive" 
		"Scotland is wet"
		"Bears don't behave nicely in the woods" 
	}
} 

testif() 

end

Nick 
n.j.cox@durham.ac.uk 

Thomas Jacobs

I am trying to determine whether an if block is acceptable in mata
without an else block even if else is empty.

In the Stata manual for if it specifically shows the following - I am
ignoring the single line if statement command:

if exp {

 multiple commands

}

which...MAY be followed by else etc.

However in the mata manual only the single line line if(exp) sttmnt 1
is displayed.  All the other examples have a trailing else whether  in
block or single line form.  In the description, however, it states "if
evaluates the expression, and if it is true, if executes the statement
or statement block that immediately follows it; otherwise, if skips
the statement or block."

I interpret the latter description to be that one can use the if block
without a trailing else.

The lack of precision is frustrating, however, and I am struggling to
interpret odd program behavior.  Can anyone definitively state whether
the following is proper programming form for mata:

if (exp) {

multiple statements

}

with no trailing empty

else{
}

?  Thanks.


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index