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
Christopher Baum <[email protected]>
To
"[email protected]" <[email protected]>
Subject
re: st: passing a function name as an argument to another function in Mata
Date
Tue, 23 Aug 2011 20:26:40 -0400
<>
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/