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" <[email protected]>
To   <[email protected]>
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
[email protected]

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index