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

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

From |
Dani Tilley <tilleydani@yahoo.com> |

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

Subject |
st: Referring to elements of a varlist in a program |

Date |
Thu, 8 Jul 2010 20:57:05 -0700 (PDT) |

Hi, I'm trying to write a program that will automate some commands, but to increase its usability I need to include 2 variables in the syntax. I need to figure out a way to refer to a user-specified variables and manipulate them in the body of the program. For instance, if the user were to specify two variables -example var1 var2- ,my program would find the mean for each and divide the sum of the means by the standard deviation of the second variable. (this is just an exercise, it doesn't mean anything) I've declared the following program example, rclass version 10.0 syntax varlist(min=2 max2) loc m=0 foreach v of varlist `varlist' { qui su `v',mean loc m=`m'+`r(mean)' } qui su varlist[2] ///I don't know how to refer to this local sd = `r(sd)' local final = `m' / `sd' drop m sd return local final = `final' end Any help is appreciated. DF Tilley * * 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/

**Follow-Ups**:**Re: st: Referring to elements of a varlist in a program***From:*Dani Tilley <tilleydani@yahoo.com>

**Re: st: Referring to elements of a varlist in a program***From:*Eric Booth <ebooth@ppri.tamu.edu>

- Prev by Date:
**st: two-tailed tests** - Next by Date:
**Re: st: Referring to elements of a varlist in a program** - Previous by thread:
**st: two-tailed tests** - Next by thread:
**Re: st: Referring to elements of a varlist in a program** - Index(es):