Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • results of a selectindex: is it a pointer or scalar

    I am trying to locate an element of a matrix and extract its row index with selectindex function. However, when the selectindex is empty, I cannot figure out how to evaluate that condition. See the following example:
    Code:
    mata
    y=2004::2010
    y[3,1]=.
    y
    row=selectindex(y[.,1]:==2007)
    row!=0
    row=selectindex(y[.,1]:==2006)
    // now row is niether zero or empty and I cannot find a way to evaluate if condition based on the value of row. see
    row!=0
    row!=.
    row!=""
    my question is how can I write and IF condition that see whether row is empty or not.

  • #2
    It returns an empty matrix if no rows/columns satisfy the condition. Test whether the number of rows or columns is different from 0 (in your case you should test the number of rows)

    Code:
    if (rows(row)!=0)

    Comment


    • #3
      Fantastic, thank you.

      Comment

      Working...
      X