You are not logged in. You can browse but not post. Login or Register by clicking 'Login or Register' at the top-right of this page. For more information on Statalist, see the FAQ.
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