Statalist


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

Re: st: string calculation


From   [email protected] (William Gould, StataCorp LP)
To   [email protected]
Subject   Re: st: string calculation
Date   Thu, 17 Jan 2008 14:26:30 -0600

Tanaka Yoshi <[email protected]> asks, 

> I have a question about the matrix calculation in the form of string.
> [...]
> 
>         . mata
>         : X=("a","b")
>         : Y=("c","d")
>         : Z=X+Y
>         : Z
>                 1    2
>             +-----------+
>           1 |  ac   bd  |
>             +-----------+
>         : end
> 
> the result is (ac, bd), but the expression i want to get is (a+c, b+d).

I assume Tanak means that the result is ("ac", "bd") and what he wants 
is ("a+c", "b+d").  One solution is 

        : Z = X :+ "+" :+ Y

        : Z
                 1     2
            +-------------+
          1 |  a+c   b+d  |
            +-------------+

Above I used the :+ operator, see -help [m2] op_colon-.

Another solution is 

        : Z = X + ("+", "+") + Y 

        : Z 
                 1     2
            +-------------+
          1 |  a+c   b+d  |
            +-------------+

-- 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