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: passing a function name as an argument to another function in Mata


From   Zurab Sajaia <[email protected]>
To   statalist <[email protected]>
Subject   RE: st: passing a function name as an argument to another function in Mata
Date   Wed, 24 Aug 2011 09:13:04 -0400

Thanks Kit,
 
This will definitely work but it means that I'm calling stata routine from mata (my caller procedure is in mata) that does nothing other that passing arguments back to a mata function...not the most beautiful solution I guess but whatever works :)
 
Thanks again,
zurab
 

----------------------------------------
> From: [email protected]
> To: [email protected]
> Date: Tue, 23 Aug 2011 20:26:40 -0400
> Subject: re: st: passing a function name as an argument to another function in Mata
>
> <>
>
> I'm trying to write a function that receives name of another function as an argument and executes it.
>
>
> Section 14.4 of ITSP, Passing a function to a Mata function, discusses that. In the call,
>
> mata: aggreg2("‘varlist’", "‘newvar’", ‘per’, "‘op’", &‘trfn’(), "‘touse’")
>
> where local trfn is the function name (in this case it can handle several, as the user specifies) and then in the header for aggreg2,
> the argument shows up as
>
> pointer(real scalar function) scalar f,
>
> and is invoked within the Mata function as
>
> v1t = (*f)(v1)
>
> in order to transform colvector v1 into v1t.
>
> Note that you cannot pass the name of a builtin function, but you probably don't want to do that anyway.
>
> Kit
>
> Kit Baum | Boston College Economics & DIW Berlin | http://ideas.repec.org/e/pba1.html
> An Introduction to Stata Programming | http://www.stata-press.com/books/isp.html
> An Introduction to Modern Econometrics Using Stata | http://www.stata-press.com/books/imeus.html
>
>
>
>
> *
> * 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