Announcement

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

  • matewmf/matmap with missing values: use capture?

    Dear list members,

    a question about matewmf or its subsequent version matmap, both from SSC. These commands can return the error r(504), 'matrix would have missing values'. However, the description of the error says that "This return code is now infrequently used because, beginning with version 8, Stata now permits missing values in matrices". My question is: given the current legality of missing values in matrices, would capture successfully execute the code previously stopped by this error (assuming of course no other error occurs)? For various reasons, I'd like to get this information from those who already know, rather than by trying with my code - including that there may be reasons not to do it that are not immediately evident.
    I'm using StataNow/MP 18.5

  • #2
    matmap from SSC is a command I wrote in 2000. I've not used it myself for many years.

    Perhaps if you edit a copy of the code and change the version stated it might work. But as you're working in Stata 17 there will be better ways to do what you want if you spell out what that is.

    Comment


    • #3
      capture won't help here, I believe. But you need to give a reproducible example of what you are trying for me to give better advice.

      Comment


      • #4
        Thanks Nick Cox. I was storing into matrices sets of scalars from a command which had to be ran A x N times for N variables. I was using a code such as

        Code:
        local j=1
        foreach var in `vars' {
        command saving r(result)
        mat name[1,`j'] = r(result)
        }
        local ++j
        mat name[1,`j'] = `anotherfinalvariable'
        mat colnames name = `vars' anotherfinalvariablename
        matewmf name name, f(abs)
        Initially my attention was focused on trying to make the matrix accept the missing value, because of the error message and because I knew (without fully reflecting on it) that I had already conditioned the `vars' on the type of the sample so as to loop only over relevant variables... but this clearly meant that something else was going on. And the reason why some missing value was generated was in fact different, gratuitous and therefore I simply corrected that. But in the meanwhile I did try capture, and it seems to me that it was working - although to be honest, now I don't even remember clearly because as soon as I was trying I spotted the real root of the problem : |
        Last edited by Matteo Pinna Pintor; 17 Jul 2023, 05:08.
        I'm using StataNow/MP 18.5

        Comment


        • #5
          To get absolute values out of a Stata matrix that includes missing values, push it into Mata, run abs() over it, and pull it back.

          Code:
          . matrix foo = (1,2,3\-1,-2, .)
          
          . mat li foo
          
          foo[2,3]
              c1  c2  c3
          r1   1   2   3
          r2  -1  -2   .
          
          
          
          . mata : st_matrix("foo", abs(st_matrix("foo")))
          
          . mat li foo
          
          foo[2,3]
              c1  c2  c3
          r1   1   2   3
          r2   1   2   .

          Comment


          • #6
            Heh, I don't use Mata - but ok, this suggests I should at some point venture into that too. Thanks for the illustration.
            I'm using StataNow/MP 18.5

            Comment


            • #7
              You use Mata. You just don't know about it yet.

              A different point is given Mata's availability that I won't enhance commands like matmap. They were perhaps useful to some people for some years, which is as much as can be hoped for most community-contributed commands, but that is it.

              Comment

              Working...
              X