Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: [Mata] passing a function to mata (new question)


From   "Jann Ben" <[email protected]>
To   <[email protected]>
Subject   st: [Mata] passing a function to mata (new question)
Date   Thu, 25 Aug 2005 22:18:16 +0200

There is another issue with passing functions. 
Suppose, the following code

	function me1(string scalar he)
	{
      	...
		if (he=="he1") y = me2(x, &he1())
		else if (he=="he2") y = me2(x, &he2())
		else if (he=="he3") y = me2(x, &he3())
		...
		return(...)	
	}

where 

	function me2(x, he)
	{
	      ...
		y = (*he)(x)
		...
		return(...)	
	}

Is it possible to change -me1()- such that 
the different -he-'s do not have to be typed out
explicitly?

If Mata had macro expansion, I would type

	function me1(string scalar he)
	{
      	...
		y = me2(x, &`he'())
		...
		return(...)	
	}

However, such things don't work in Mata. Does anyone
know a solution to this problem?

ben


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index