Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    One other thing Joseph (#13)--you're right, there was another command with *_`i' that was causing the problem--it was after the first close brace from the first set of Mata commands.

    JT

    Comment


    • #17
      Originally posted by John Mullahy View Post
      To get broader attention I wonder if this discussion should move out of the Mata forum and into the general Stata forum since the central concern seems to be a "Stata issue" and not a "Mata issue."
      Do you have any other examples where while fails? I couldn't get it to fail in any other circumstance except where Mata is invoked in exactly the manner shown in this thread. In the code below, the only circumstance where while gets tripped up is the very last,
      Code:
      version 17.0
      
      clear *
      
      *
      * if
      *
      while 0 {
      
          if 0 {
              mata: printf("Mata here\n")
          }
      
          display in smcl as text "Stata here"
      
      }
      
      *
      * if elseif else
      *
      while 0 {
      
          if 0 {
              mata: printf("Mata here\n")
          }
          else if 0 {
              mata: printf("Mata here\n")
          }
          else {
              mata: printf("Mata here\n")
          }
      
          display in smcl as text "Stata here"
      
      }
      
      *
      * quietly
      *
      while 0 {
      
          quietly {
              mata: printf("Mata here\n")
          }
      
          display in smcl as text "Stata here"
      
      }
      
      *
      * capture
      *
      while 0 {
      
          capture {
              mata: printf("Mata here\n")
          }
      
          display in smcl as text "Stata here"
      
      }
      
      *
      * foreach
      *
      while 0 {
      
          foreach dummy in "a" "b" {
              mata: printf("Mata here\n")
          }
      
          display in smcl as text "Stata here"
      
      }
      
      *
      * foralues
      *
      while 0 {
      
          forvalues i = 1/2 {
              mata: printf("Mata here\n")
          }
      
          display in smcl as text "Stata here"
      
      }
      
      *
      * mata {}
      *
      while 0 {
      
          mata { printf("Mata here\n") }
      
          display in smcl as text "Stata here"
      
      }
      
      *
      * mata {
      * }
      *
      while 0 {
      
          mata {
              printf("Mata here\n")
          }
      
          display in smcl as text "Stata here"
      
      }
      
      exit
      Like William in #7, I didn't see any explicit reference in at least the online help files for Mata to a
      Code:
      mata {
          . . . .
      }
      syntax for invoking Mata, and it's conspicuously absent from help m3 mata in the ways enumerated there for invoking Mata.

      The closest to it is in the penultimate syntax in the code above, where the brace pair is on the same line, which can be inferred from one definition of stmt := { stmt ... } shown in help m2_syntax. And that syntax executes without error when I run the code above.

      So, to me it does seem to be some edge case of an interaction of Stata's while syntax and an undocumented (and unsanctioned) Mata-invocation syntax.

      Comment


      • #18
        @Niels's solution worked perfectly for me. Thanks!

        Comment

        Working...
        X