Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
Nick Cox <njcoxstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: question regarding Syntax command |

Date |
Mon, 25 Jun 2012 17:52:34 +0100 |

On #1, if you want to write a non-trivial Stata program, then at some point you have to look up what you need in the help for -syntax-. You don't have to understand it all. program MyFunc syntax varlist , genvar(str) ... generate `genvar' = ... end is a step closer to what you want. The -syntax- statement here is that an option -genvar()- is required which takes a string argument. On #2, the short answer is No -- in Stata. If from MATLAB experience you prefer to work that way, you can do so in Mata. In general, clear communication is easier if you realise that programs in Stata are not called "functions". See also http://www.stata.com/statalist/archive/2008-08/msg01258.html Nick On Mon, Jun 25, 2012 at 5:10 PM, Pradipto Banerjee <pradipto.banerjee@adainvestments.com> wrote: > Assume a code for an ado file is as follows: > > program define MyFunc > ... > gen MyOutVar = ... > end > > the function MyFunc was a few variables can be called as "MyFunc MyInVar1 MyInVar2" and then after calling the function a column MyOutVar is generated in the database. > > (1) I want to the MyFunc written in Stata to take the output variable MyOutVar as a input, i.e. instead of defining "gen MyOutVar" I want to let the user choose the variable name corresponding. Can I potentially define an "option" like "genvar(MyOutVar)" while calling the function MyFunc, i.e. call the function as "MyFunc MyInVar1 MyInVar2, genvar(MyOutVar)" > > How can I implement this? > > > (2) I am used to Matlab where once we define a functions say MyFunc and the functions is supposed to return a variable, then we call them as MyOutVar = MyFunc (MyInVar1, MyInVar2, ...). It is possible to do the same in Stata, i.e. can I define a Stata program to recognize the "=" sign as a part of the syntax, and the function is called as "MyOutVar = MyFunc (MyInVar1, MyInVar2)" ? * * 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: question regarding Syntax command***From:*Pradipto Banerjee <pradipto.banerjee@adainvestments.com>

- Prev by Date:
**st: FW: RE: RE: RE: Interpreting Kleibergen Paap weak instrument statistic** - Next by Date:
**st: RE: RE: RE: RE: Interpreting Kleibergen Paap weak instrument statistic** - Previous by thread:
**st: question regarding Syntax command** - Index(es):