Statalist


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

Re: st: Mata r() strings


From   "Ben Jann" <[email protected]>
To   [email protected]
Subject   Re: st: Mata r() strings
Date   Sun, 26 Aug 2007 21:19:27 +0200

I don't think string scalars can be returned in r(). But this doesn't
matter because macros can. Your function should be:

void function my_test() {
    st_global("r(my_name)" ,"my_value")
}

-help mata st_numscalar()- should be more clear about this.

ben

On 8/25/07, Sergiy Radyakin <[email protected]> wrote:
> Dear Statalisters,
>
> I want to return a string among the r() values from a Mata function.
>
> According to the manual, the following function is to be used in this case:
> st_strscalar(string scalar name, string value)
> (see help st_numscalar)
>
> The manual says that "1. All functions allow name to be ... r() scalar
> such as r(mean)"
>
> It does not seem to work however. The following is what happened:
> **-------------1------------------------------------------------------------------------------
> : mata clear
> : void function my_test() {
> > st_strscalar("r(my_name)" ,"my_value")
> > }
> : my_test()
>           st_strscalar():  3300  argument out of range
>                my_test():     -  function returned error
>                  <istmt>:     -  function returned error
> r(3300);
>
> As an alternative, I tried to store my string value to a local via st_local:
> **-------------2------------------------------------------------------------------------------
> : mata clear
> : void function my_test() {
> > st_local("r(my_name)" ,"my_value")
> > }
> : my_test()
> _r(my_name) invalid name
>               st_local():  3300  argument out of range
>                my_test():     -  function returned error
>                  <istmt>:     -  function returned error
> r(3300);
>
> Finally, to make sure the problem is related to strings I tried the numbers:
> **-------------3------------------------------------------------------------------------------
> : mata clear
> : void function my_test() {
> > st_numscalar("r(my_name)" ,123)
> > }
> : end
> . mata my_test()
> . return list
> scalars:
>            r(my_name) =  123
> **--------------------------------------------------------------------------------------------
>
> My question is: does st_strscalar() work as described in the manual? Can
> anyone provide an example, please?
>
> If it does not work or serves a different purpose, what is a way to
> return strings
> as r() values from Mata? (I know I can write to local or global
> macros, this is not
> an issue here, I want to write to r()).
>
> Thank you,
>      Sergiy Radyakin
> *
> *   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/
>
*
*   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