Statalist


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

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


From   Phil Schumm <pschumm@uchicago.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Should be simple yet ... how to write a function?
Date   Wed, 18 Feb 2009 04:31:54 -0600

On Feb 18, 2009, at 4:03 AM, Fabrice wrote:
Im a pretty advanced Stata user, but have a simple question I cant figure out: how does one write a *function*, i.e. a program that returns a value, and that can be called like local y = fct(x), where x and y are numbers or strings.


You don't, at least not in Stata. You can write a function for use with -egen-, however, while some users have gotten a lot of mileage out of this, most people who ask about writing their own functions are looking to make use of them in contexts where -egen- won't help.

Note that you *can* write your own functions in Mata. Moreover, depending on what you're doing, Mata may offer other advantages as well (e.g., speed).


-- Phil

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



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