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: Mata and do files


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Mata and do files
Date   Wed, 10 Aug 2011 22:23:59 +0100

"price length weight" is not an acceptable argument for -st_view()-.
You need to tokenize it.

I imagine that the do-file approach requires you to leave Mata with an
-end- statement.

Nick

On Wed, Aug 10, 2011 at 10:14 PM, Alex Olssen <[email protected]> wrote:
> Dear Nick,
>
> You are absolutely correct - it was Statalist.
>
> I am not sure what you mean by "try tokens("price length weight")."
>
> I looked at the help file and then tried the following, which again
> works interactively but not from a do file...
>
> sysuse auto, clear
> mata
> real scalar theta()
> {
> st_view(a = ., ., tokens("price length weight"))
> a_cov = variance(a)
> a_eigen = symeigensystem(a_cov, X = ., L = .)
> return(L[1]/sum(L))
> }
> theta()
>
> Any ideas?
>
> On 10 August 2011 23:54, Nick Cox <[email protected]> wrote:
>> It's not Stata that bounces your emails; it's Statalist!
>>
>> Try
>>
>>  tokens("price length weight")
>>
>> Nick
>>
>> On Wed, Aug 10, 2011 at 12:39 PM, Alex Olssen <[email protected]> wrote:
>>> Hi everyone,
>>>
>>> Apologies to anybody who gets this message twice - I just got an email
>>> from Stata telling me my first message was bounced.  I checked the
>>> archive and it doesn't appear to have arrived correctly.  In any
>>> case...
>>>
>>> I am trying to learn some Mata and am having difficult running Mata
>>> code from a do file.
>>>
>>> For example I can use the following code interactively, but if I try
>>> run it from the do-file editor I get error r(3000).  I have looked
>>> around for an answer in [M] and the Statalist archives to no avail.
>>>
>>> sysuse auto, clear
>>> mata
>>> real scalar theta()
>>> {
>>> st_view(a = ., ., "price length weight")
>>> a_cov = variance(a)
>>> a_eigen = symeigensystem(a_cov, X = ., L = .)
>>> return(L[1]/sum(L))
>>> }
>>> theta()
>>>
>>> Any help would be greatly appreciated.
>>
>> *
>> *   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/
>

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index