Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: dynamic line execution in mata


From   Nick Cox <njcoxstata@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: dynamic line execution in mata
Date   Mon, 10 Feb 2014 17:59:21 +0000

You are presuming that such a thing exists.

In essence, Mata has no direct equivalent of macro substitution.

Sometimes, the way to solve (similar) problems is by direct
manipulation of strings. That is the theme of

SJ-11-2 pr0052  . . . . Stata tip 100: Mata and the case of the missing macros
        . . . . . . . . . . . . . . . . . . . . . . . . W. Gould and N. J. Cox
        Q2/11   SJ 11(2):323--324                                (no commands)
        tip showing how to do the equivalent of Stata's macro
        substitution in Mata

Sometimes, using pointers is the answer.

In this case, I'd guess that you want the Mata equivalent of some
Stata operation and that there's a Mata way of doing it, but I would
rather hear whether that is so than try to guess what the underlying
problem is.

Nick
njcoxstata@gmail.com


On 10 February 2014 17:38, Andrew Maurer <Andrew.Maurer@qrm.com> wrote:
> Hi Statalist,
>
> I am trying to find Mata's equivalent of Stata's macro expansion functionality. In the below example, I first define an object thisvar as the string "date" and I define the object date as the column vector 1 \ 2 \ 3 \ 4 \ 5. How can I return the contents of the "date" object by only referencing "thisvar"?
>
> In the line, rows( thisvar ), thisvar is simply the 1x1 matrix containing the string "date", so rows( thisvar ) returns: 1. What I am looking for is something like rows( `=thisvar' ), so as to return 5 rather than 1.
>
> ********* begin example *********
>
> mata
>
> i = 1
> date = 1 \ 2 \ 3 \ 4 \ 5
> varnames = "date", "price"
> thisvar = varnames[1,i]
> rows( thisvar ) // output: 1
> rows( date ) // output: 5
>
> end
>
> ********* end example ***********
>
> Thank you,
> Andrew Maurer
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index