Title | Fixing bugs in Mata | |
Author | William Gould, StataCorp |
When you review the official source, you might spot a bug. If you do, naturally, you will report it to us (see Stata Technical Services). Then we can fix the problem and issue an update.
In the meantime, you might want to fix the bug yourself.
What follows is technical. You may want to skip reading it until you need it.
If you wish to continue, say three times to yourself, “Mata’s official code does not have bugs.” Now look again at what you thought was a bug. It has probably vanished. We find that works for us in most cases; what we thought was a bug was caused by our own confusion. Nevertheless, bugs do occur, and sometimes you cannot wait for the official fix. In that case, perform the following steps:
copysource is not documented in the manuals, but you can access it via Stata’s Command window by typing help copysource.
. copysource helloworld.mata
. doedit helloworld.mata
. mata: mata clear . do helloworld.mata
mata mosave is documented in [M-3] mata mosave. The above will save helloworld.mo in the current directory. You may prefer to save it in your personal directory:
. mata: mata mosave helloworld()
. mata: mata mosave helloworld(), dir(PERSONAL)
. mata: mata set matamofirst on
. mata: mata set matamofirst on, permanently
Be careful about that, however, because now, when StataCorp fixes helloworld(), and you install the update, Mata will continue searching the .mo files first. You will end up using your version and not the the updated version in the library. You will need to remember to
. mata: mata set matamofirst off, permanently
after installing the official update.
At that point, you will want to erase helloworld.mo, too, but, if you forget, it will not matter because Mata will be back to searching its libraries first.
Function helloworld() is actually part of official Mata:
. helloworld() hello, world
If you need to fix a bug, we suggest you practice modifying helloworld.mata before working on a real file.