No announcement yet.
  • 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:
    and other, mostly in codes of Elliott Lowy (as far as I can identify)

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

    Thank you, Sergiy

  • #2
    . 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)


    • #3
      Thank you, William!
      Found it in as you've pointed.


      • #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.


        • #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):

          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!
                  for (m=length(m2);m;m--) tf[m]=m2[m]!=NULL
              else tf=maybe:!=0:&maybe:<.
          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