[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: RE: Should be simple yet ... how to write a function?

From   "Nick Cox" <>
To   <>
Subject   st: RE: RE: Should be simple yet ... how to write a function?
Date   Wed, 18 Feb 2009 18:00:38 -0000

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. 



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
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
sounds like a good idea.

Then I noticed that some simple scalar function (such as acos()) appear
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
and it responds that it is not a built in or ado-file. So where is it

Maybe that is all implemented in C code in the kernel, and then, I'm
But it does not hurt to ask...

Martin Weiss


*   For searches and help try:

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