st: re: programming new function

To the best of my knowledge, it is not possible to program a new
function on
its own.
Of course, it is possible to modify any official command that StataCorp
writes as an ado file; but I think this "hacking" is risky and not
recommended. Of course, you could create a copy of the command (e.g. you
could make a copy of egen, call it egen2) and than modify the copy using
standard -syntax-. According to the difficulty of the command you are
modifying, this way could be quite difficult too.
Another way that might work on occasion is to write a new command
"wrap-around".

Partially right. Functions that appear in 'help functions' are those
used by GENERATE, and the generate command cannot be extended by users
to apply new functions. Those functions are coded in C, and are thus
quite efficient. Functions that appear after the command EGEN (Extended
GENerate) may be either provided by StataCorp or user-written; e.g.
findit egenmore for a large library of such functions. You need NOT
duplicate official egen.ado, since it is merely a wrapper for those
functions. If you create a file _gzap.ado on the adopath, you will be
able to use the 'zap' function with egen.

The downside of egen functions is that they are interpreted code, and
if they are doing a lot of work they may be quite slow. That is
presumably one of the disadvantages that Stata 9's 'mata' matrix
programming language may be able to address.