I've unsuccessfully searched for a nice way to check whether a Mata function exists in the user's Stata/Mata, and conditionally execute Mata code depending on that check. Although I can imagine various ways in which this need might arise, I've encountered it in the context of wanting to use the recently instituted undocumented built-in function vech_lower() if the user's Mata recognizes that function, and do the calculation another way if it does not. All I can think of is to try the function on some minimal valid argument and see what happens:
This seems clumsy, so I presume I'm just not finding some simple Mata function to check if some other function exists. This existence might or might not depend on the Stata version, so a call to stataversion() won't in general help here.
Thanks, Mike
Code:
mata: // try to use vech_lower() with valid toy input and let Stata capture any error err = _stata("mata: vech__lower((1,1)\(1,1))",1) if (err ==0 { // perform calculation using vech_lower() ... } else { // perform calculation some other way ... } end
Thanks, Mike
Comment