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

From |
"Joseph Coveney" <jcoveney@bigplanet.com> |

To |
<statalist@hsphsun2.harvard.edu> |

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

Date |
Wed, 18 Feb 2009 23:11:26 +0900 |

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. This seems it should be available somewhere in the language, yet I?ve searched in a lot of programming explanations about Stata and never found a way to write that. FYI, I program extensively in stata, know about r-type vs. e-type program, and know how to store results to return to main program. I just don?t know how to write the most simple function form. Any idea? Fabrice ---------------------------------------------------------------------------- ---- As others have already mentioned, there isn't much in Stata for a user-written function for use with -generate-, because of the way Stata vectorizes that command. But, using Stata's class programming (-help classman-), you can create user-written functions for use on the right-hand side of an equals sign for just about anything else, e.g., assignment to macro variables (as in your example), scalars, matrixes, and objects and their member variables. You can also use them in the list of arguments of other user-written functions for evaluation during the call, or you can pass the function itself in its container object. Joseph Coveney * * 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/

**References**:**st: Should be simple yet ... how to write a function?***From:*"Fabrice" <fcaspam@yahoo.fr>

- Prev by Date:
**Re: st: How to write a fast code to obtain a specific calculation** - Next by Date:
**Re: st: AW: simple question on two-way table** - Previous by thread:
**RE: st: Should be simple yet ... how to write a function?** - Next by thread:
**st: How to write a fast code to obtain a specific calculation** - Index(es):

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