Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Parsing of multiple -if- lines


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Parsing of multiple -if- lines
Date   Tue, 13 Aug 2002 13:57:08 +0100

Nick Winter

Am I missing something obvious, or is there something weird about how
Stata chokes on the following program -mytest-, but does not choke on
-mytest2-?  That is, using a macro to selectively comment out lines of
code seems to work, except when it is within an -if- block :

program define mytest
   if `1'== 1 {
	`2' if `3'== 1 {
	`2'	di "three is set to one"
	`2' }
   }
   else {
	`2' if `3'== 1 {
	`2'	di "three is set to one"
	`2' }
   }
end

prog define mytest2

	`2' if `3'== 1 {
	`2'	di "three is set to one"
	`2' }

end

. mytest 1 " " 1
three is set to one
unrecognized command:  } invalid command name
r(199);

. mytest 1 "*" 1
unrecognized command:  } invalid command name
r(199);

. mytest2 1 " " 1
three is set to one

. mytest2 1 "*" 1

>>> Stata expects there to be something within an -else-.
In principle, it is not an error to ask Stata to
do nothing. In practice, an -else- branch with nothing
in it is, I guess, usually a programmer error.

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

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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   |   What's new   |   Site index