All Stata functions, strict sense, such as -sin()- or -acos()- are
implemented as part of the executable, or other hidden code, and as such
their internals are not visible to the user. You are not missing that
much, as you couldn't emulate that way of programming any way.
You are replying to a posting by Martin Weiss, which referred you to an
article which says more about functions, and also more about -egen-
functions. It is accessible on-line, as the URL he gave implies.
Nick
[email protected]
Fabrice
Thanks to all of you for your thoughtful answers!
I've learned much, including--but not restricted to--...
a) that most experts agree that Stata indeed does not implement the most
basic form of programming (function passing direct return values)
b) that Stata has a wonderful programming language with Mata (I had read
about it, but it's impressive what is a priori possible there)
c) that Stata has an object oriented engine (hidden behind the class
structure), whoa!
What is still unclear to me is the following: Maarten suggested that I
could
make function returning variables, like many egen function. And the
trick is
simply to look into the .ado code of those _gxxx.ado functions. After
looking briefly at such code, I'm still not clear about the details, but
it
sounds like a good idea.
Then I noticed that some simple scalar function (such as acos()) appear
also
there in the library provided by Stata, and wondered: hey, why not just
imitate what's there?!
Currently, the only example I can find are Mata code.
So my remaining question is therefore: I know I can write
. scalar y = sin(x)
So .... where is the code for such "sin" function. I tried ". which
sin",
and it responds that it is not a built in or ado-file. So where is it
defined?
Maybe that is all implemented in C code in the kernel, and then, I'm
toast.
But it does not hurt to ask...
Martin Weiss
See http://www.stata-journal.com/article.html?article=pr0007
*
* 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/