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

st: re: programming new function


From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: re: programming new function
Date   Sat, 16 Apr 2005 21:29:38 -0400

Renzo replied to Jean-Benoit with

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.

Kit Baum, Boston College Economics
http://ideas.repec.org/e/pba1.html

*
* 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