December 2025 – update
Thanks to a user comment below, it seems Stata have changed st_view’s behaviour, and the two example problems in my original post below now (at least as of version 19.5) now give the results I had originally expected to get.
Original post follows
I use Stata a lot, and I think it’s a great package. An excellent addition a few years ago was the Mata language, a fully fledged matrix programming language which sits on top or separate from Stata’s regular dataset and command/syntax structure. Many of Stata’s built in commands are programmed using Mata, I believe. I’ve been using Mata quite a bit to program new commands, and in the process have come across some strange behaviour in the st_view function in Mata which I think can cause real difficulties (it did for me!). This post will hopefully help avoid others ending up with the problems I did.