Statalist


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

st: Mata r() strings


From   "Sergiy Radyakin" <serjradyakin@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: Mata r() strings
Date   Fri, 24 Aug 2007 19:18:52 -0400

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/



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