Announcement

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

  • loop and mata

    hello, i need to run the function mata inside a foreach, but when i give the end to mata, it breaks the loop, does anyone know how i can correct this?

  • #2
    If you want
    • a block of Mata code terminated by end
    to run within
    • a Stata block surrounded by braces {} - typically a program, but in fact within any brace-enclosed block of code, such as a loop
    you need to
    • define your Mata code as a Mata function outside the brace-enclosed block
    • call the Mata function within the brace-enclosed block
    Even though your "end" is meant to terminate a Mata block, at the time Stata is parsing the loop, the fact that the "end" belongs to Mata and not to Stata is not recognized, and causes Stata to react incorrectly.

    Comment


    • #3
      Cross-posted at https://www.statalist.org/forums/for...-loop-and-mata

      There are now two answers there, so please follow there if interested

      Comment

      Working...
      X