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

st: RE: Parsing of multiple -if- lines


From   "Nick Winter" <[email protected]>
To   <[email protected]>
Subject   st: RE: Parsing of multiple -if- lines
Date   Tue, 13 Aug 2002 12:33:19 -0400

> -----Original Message-----
> From: Nick Cox [mailto:[email protected]] 
> Sent: Tuesday, August 13, 2002 8:57 AM
> To: [email protected]
> Subject: st: Parsing of multiple -if- lines
> 
> 
> 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]

My first thought as well.  In fact, however, the following fails too:

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

When the -else- clause is removed, then the program crashes only when
the second token is set to an asterisk, suggesting that it is the
comments in there that are somehow confusing things?

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