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: On calling a mata-defined function in Stata
From
Dorothy Bridges <[email protected]>
To
[email protected]
Subject
Re: st: On calling a mata-defined function in Stata
Date
Wed, 11 May 2011 23:35:12 -0700
Thanks very much!
On Wed, May 11, 2011 at 9:04 AM, Austin Nichols <[email protected]> wrote:
> Dorothy Bridges <[email protected]>:
> I guess you refer to
> http://www.stata.com/statalist/archive/2009-04/msg00976.html
> which is worth referencing as it contains a lot of material.
>
> Mata is more elegant for more difficult problems, but try:
>
> clear all
> mata:function f(x) return(x^2+2*x)
> sca x=5
> mata:st_numscalar("y",f(st_numscalar("x")))
> di x,y
>
>
> On Wed, May 11, 2011 at 10:19 AM, Dorothy Bridges <[email protected]> wrote:
>> I found in the archives the following comment regarding calling a
>> function in Stata: "or you can write a Mata function which you call
>> from Stata ... [which] is often more elegant." I've tried
>> unsuccessfully to find instructions on how exactly to go about this.
>> What I'd like to do, I think, is:
>>
>> Mata:
>> function f(x) return(x^2+2x)
>>
>> In Stata
>> sca x=5
>> sca y=&f(x)
>>
>> But, clearly, I don't know what I'm doing. Many thanks in advance.
>
> *
> * 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/