Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: mata's st_data


From   joe j <joe.stata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: mata's st_data
Date   Fri, 10 Sep 2010 22:59:22 +0200

Thanks so very much for your further help. (I couldn't figure out
though the need for the ",." at the end; the code worked without them
as well.)
J.

On Fri, Sep 10, 2010 at 9:41 PM, Tirthankar Chakravarty
<tirthankar.chakravarty@gmail.com> wrote:
> Joe,
>
> I had to update my neglected copy of Stata 10.1 for this one, and
> while the help file for -st_macroexpand()- hasn't changed between
> Stata 10.1 and Stata 11.1, the code I sent you works in the latter,
> but not in the former.
>
> Turns out that in Stata 11, you don't need -st_macroexpand()- at all. The code:
>
> *******************************************
> clear*
> set obs 10
> foreach x of newlist a b c d {
>       g var_`x' = runiform()
> }
> li
> mata
> st_data(.,"var_*",.)
> end
> *******************************************
>
> is smart enough to do what you want it to do. The -st_macroexpand()-
> was gratuitous in the code I sent you. For Stata 10.1, then you can
> try this clumsy workaround by putting the variables you want into
> locals beforehand:
>
> *******************************************
> clear*
> set obs 10
> foreach x of newlist a b c d {
>       g var_`x' = runiform()
> }
> li
> unab varnames:  var_*
> mata
> st_data(., tokens(st_local("varnames")),.)
> end
> *******************************************
>
> There has to be a better solution for Stata 10 - I can't think of it right now.
>
> T
>
> 2010/9/10 joe j <joe.stata@gmail.com>:
>> Many thanks, Tirthankar.  But has this code worked for you? I am
>> getting an error:
>> var_* invalid name
>>
>> I am using Stata SE versin 10.1
>>
>> On Fri, Sep 10, 2010 at 3:59 PM, Tirthankar Chakravarty
>> <tirthankar.chakravarty@gmail.com> wrote:
>>> Use -st_macroexpand()-:
>>> *******************************************
>>> clear*
>>> set obs 10
>>> foreach x of newlist a b c d {
>>>        g var_`x' = runiform()
>>> }
>>> li
>>> mata
>>> st_data(.,st_macroexpand("var_*"),.)
>>> end
>>> *******************************************
>>>
>>> T
>>>
>>> On Fri, Sep 10, 2010 at 6:47 AM, joe j <joe.stata@gmail.com> wrote:
>>>> I was wondering if there is a way to use wildcard for variable names
>>>> in mata's "st_data" function. I have a large number of variables, like
>>>> US_ctry, UK_ctry, etc, all of which could be defined in Stata as
>>>> "*ctry".
>>>>
>>>> But when I try the following in mata:
>>>> A  =  st_data(.,("*ctry")).
>>>>
>>>> I get the warning:
>>>>
>>>> *ctry invalid name
>>>>
>>>> The (tedious) alternative is: A  =  st_data(.,("US_ctry", "UK_ctry")
>>>>
>>>> Any suggestion would be appreciated, because the number of variables
>>>> are too many.
>>>>
>>>> Joe
>>>>
>>>> *
>>>> *   For searches and help try:
>>>> *   http://www.stata.com/help.cgi?search
>>>> *   http://www.stata.com/support/statalist/faq
>>>> *   http://www.ats.ucla.edu/stat/stata/
>>>>
>>>
>>>
>>>
>>> --
>>> To every ω-consistent recursive class κ of formulae there correspond
>>> recursive class signs r, such that neither v Gen r nor Neg(v Gen r)
>>> belongs to Flg(κ) (where v is the free variable of r).
>>>
>>> *
>>> *   For searches and help try:
>>> *   http://www.stata.com/help.cgi?search
>>> *   http://www.stata.com/support/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/statalist/faq
>> *   http://www.ats.ucla.edu/stat/stata/
>>
>
>
>
> --
> To every ω-consistent recursive class κ of formulae there correspond
> recursive class signs r, such that neither v Gen r nor Neg(v Gen r)
> belongs to Flg(κ) (where v is the free variable of r).
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/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/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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