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".
The [P] manual is where to look. Start with -syntax-
Best,
Renzo
----------------------------------------------------------------------------
----
*From   Jean-Benoit Hardouin <[email protected]> 
To   Statalist <[email protected]> 
Subject   st: programation of a new function 
Date   Fri, 15 Apr 2005 23:47:22 +0200 
----------------------------------------------------------------------------
----
Dear all,
I search the way to write a new function (as int() or chol()... not a
command), and I have not find information about this subject in the Stata
manual. Is it possible in Stata to program a new function ? If yes, where
can I find informations ?
Thank you
Jean-Benoit Hardouin
*
*   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/