Statalist


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

Re: st: Mata r() strings


From   "Sergiy Radyakin" <serjradyakin@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Mata r() strings
Date   Sun, 26 Aug 2007 16:40:34 -0400

Hello Ben!

Thanks for your reply. I didn't understand what was the problem with
the strings in r().
  1. r() supports string results
  2. Mata works with strings
  3. There is a function to store string results into an r() -st_strscalar-
It seems that everything should have worked fine. But it didn't.

I was trying to be canonical and put the results where they belong.
And finally this document:
  http://www.stata.com/help.cgi?mf_st_global
have resolved the confusion.

I also think that the help for -st_strscalar- and -st_numscalar- could
be a bit more detailed.

Best regards,
   Sergiy Radyakin


On 8/26/07, Ben Jann <ben.jann@gmail.com> wrote:
> 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 <serjradyakin@gmail.com> 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/
>
*
*   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