Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: String comparisons in Mata


From   [email protected] (William Gould, Stata)
To   [email protected]
Subject   Re: st: String comparisons in Mata
Date   Mon, 30 Jan 2006 08:13:01 -0600

German Rodriguez <[email protected]> asked, 

> A mata question: Why is [...]
> 
> . mata: strupper("a") >= "A"
>   0
>
> . mata: strupper("a") == "A"
>   1

Answer:  There's a bug in Mata.  This is rather embarrassing because, well, 
watch this, 

        : "A" >= "A"
          0

Obviously, the result should be 1 (meaning true).   An examination of 
Mata's source code reveals the that ">=" operator is being treated 
the same as the ">" operator in the case of strings (and only in the 
case of strings).

As I said, this is rather embarrassing.  More than rather, in fact.

We will fix it.

German was discovered this when he wrote the code

        scalar function isLetter(string scalar s)
        {
                S = strupper(s)
                return(S >= "A" & S <= "Z")
        }

To work around the bug, I sugest German change his code to read 

        scalar function isLetter(string scalar s)
        {
                S = strupper(s)
                return(S > char(ascii("A")-1) & S <= "Z")
        }

-- Bill
[email protected]
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index