Announcement

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

  • Inverst function of char()

    Dear Listers,

    I am looking for a inverse function of char(). The char() function maps 90 to the character Z. There should be an inverse function which can maps Z to 90. Is there already such a function?

    Thanks

    Tony

  • #2
    Mata has an ascii() function.

    Comment


    • #3
      Yes, I know. But should there be such a function in Stata?

      Comment


      • #4
        Should? Yes, in my view.

        Comment


        • #5
          Add it to the wishlist for Stata 14. Maybe one could add the possibility to write our own functions in Stata - but I do not think this will happen.

          Best
          Daniel

          Comment


          • #6
            Tony --

            Given what Nick pointed out, you could make a little wrapper for mata that just displays/returns the character. I've also found the package "asciiplot" to be useful - it prints out a table of all the ascii characters. Anyways, this a little sloppy, but I think it works:

            Code:
            program ascii, rclass
                syntax anything
                mata: printf("Ascii code for `anything':");ascii("`anything'")
                tempname char
                mata: st_numscalar("char",ascii("`anything'"))
                return scalar char=char 
            end
            /* Try it out */
            ascii s
            return list

            Comment


            • #7
              A small cosmetic point is that tempname char seems redundant, as you never use that tempname.

              There is also scope for interactive use, here Stata calling Mata.

              Code:
               
              . mata : ascii("s")
                115

              Comment


              • #8
                thanks for the suggestions!

                Comment

                Working...
                X