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


From   Christopher Baum <kit.baum@bc.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   re:RE: st: passing a function name as an argument to another function
Date   Wed, 24 Aug 2011 10:51:45 -0400

<>
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 :)


No need--can be done entirely within Mata. See {m-2] ftof.

clear all
mata:
real function x2(real scalar x) 
{
	return(x^2)
}

void function test(
	pointer(real scalar function) scalar f,
	real scalar x)
{
	xx = (*f)(x)
	xx
}

test(&x2(), 4)

end



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/


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