Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Missing values in Mata functions


From   "Jann Ben" <[email protected]>
To   <[email protected]>
Subject   st: Missing values in Mata functions
Date   Thu, 8 Sep 2005 16:57:28 +0200

I have a general question about programming Mata functions: 
How should we deal with missing values? 

Up to now, my strategy simply was not to allow missing values. 
That is:

  : void myfunction(x) {
  >         if (missing(x)) _error(3351)
  > }
  : myfunction(.)
              myfunction():  3351  argument has missing values
                   <istmt>:     -  function returned error
  r(3351);

But I'm not sure if this is the right way to go.

In ado code, the convention is to use the -marksample- 
command to restrict the sample to the non-missing cases.
However, as far as I can see there is no such simple way
to handle missing valus in Mata.

So, what would be a good strategy? Should we take the extra
programming effort (and also waste computer time) to deal 
missing values in Mata functions? Or should it be left to 
the user to get rid of missing values before applying mata
functions?

If Mata functions should allow missing values, what would 
be a good programming approach?

This also raises another question I already posted some days 
ago on statalist: How can we quickly select a submatrix (e.g.
all non-missing elements of a vector, all rows of a matrix 
that do not contain any missing values) in Mata?

ben


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index