Announcement

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

  • Mata function -truish()-

    Dear All,

    I occasionally find the function truish() mentioned in other people's code, such as here:
    http://repec.org/bocode/h/htm.ado
    here
    http://repec.org/bocode/d/drany.ado
    and other, mostly in codes of Elliott Lowy (as far as I can identify)

    I believe truish() is not part of standard Stata:
    Code:
    . version 16.0
    
    . mata truish(1)
                     <istmt>:  3499  truish() not found
    r(3499);
    Could anyone, please, identify where is this function defined?

    Thank you, Sergiy

  • #2
    Code:
    . ssc install lowyseattle
    checking lowyseattle consistency and verifying not already installed...
    installing into /Users/lisowskiw/Library/Application Support/Stata/ado/plus/...
    installation complete.
    
    . mata truish(1)
      1

    Comment


    • #3
      Thank you, William!
      Found it in https://fmwww.bc.edu/repec/bocode/l/lowyseattle.do as you've pointed.

      Comment


      • #4
        I should have asked in post #2: Can you see the source for truish() and if so, can you post it, or at least tell us what it does, for the benefit of anyone who latter finds this topic? I couldn't quickly find it in the file you linked from post #3 - there are 300+ hits on truish in that file.
        Last edited by William Lisowski; 11 Jan 2021, 08:03.

        Comment


        • #5
          I couldn't quickly find it in the file you linked from post #3 - there are 300+ hits on truish in that file.
          I fully share your sense of desperation. When I opened the file I was overwhelmed by it. I am most certain that this file is a machine generated assembly, perhaps from multiple files that were managed separately, but combining them into one source file like this is a good way to seal the project (in all meanings). Unfortunately Stata does not provide any way of locating the DECLARATION of the function, rather than the USE of it (and the uses are almost 400 in a single file) even though the definitions are marked with comments >def func<. (which could be an artefact of the tool or editor that the author has used for this purpose).

          Still, paying attention to the patterns in the code, the truish() function can be seen around the line 10,552 of the source file (the code below is by Elliott Lowy):

          Code:
          real scalar truish(matrix maybe) { //>>def func<<
              if (!length(maybe)) return(0)
              if (eltype(maybe)=="string") tf=strlen(maybe):>0
              else if (eltype(maybe)=="pointer") { //pointers only compared in pairs!
                  m2=colshape(maybe,1)
                  tf=J(length(m2),1,.)
                  for (m=length(m2);m;m--) tf[m]=m2[m]!=NULL
                  tf=colshape(tf,cols(maybe))
                  }
              else tf=maybe:!=0:&maybe:<.
              return(sum(tf))
              }
          end
          The meta-information for the function is as following (verbatim):
          //!type: search
          //!truish: scalar true/false for real,string,pointer
          //!mabye: to eval
          //!R: sum of: (non-zero) non-missing for real; non-empty for string, non-null for pointer.


          So it looks like a generalization of true/false evaluation for arbitrary types (real, string, pointer, matrix).

          Best, Sergiy

          Comment

          Working...
          X