Statalist


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

Re: st: Passing varlist to a Program


From   "Michael I. Lichter" <MLichter@Buffalo.EDU>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Passing varlist to a Program
Date   Wed, 22 Apr 2009 00:03:25 -0400

Aaron,

Yes, it can be disturbing for somebody used to standard structured programming languages to start doing work in Stata or any of the mainstream statistics packages. It's not as disturbing as APL or BASIC, though (for different reasons).

Anyway, if you have the manuals handy, there is a section in the User's Manual about getting started in programming, and the Programming Reference Manual is a helpful supplement. There are accessible articles in the Stata Journal archives on programming, like Nick Cox's classic on programming style (http://www.statajournal.com/article.html?article=pr0018), there is a new book by Chris Baum (http://www.stata-press.com/books/isp.html), and there are the archives of this list (searchable through the Stata web site, for one) and this list itself.

As for your programming query, here's one way to do it using the -syntax- command.

version 10.1

cap program drop someprog
program define someprog
   syntax varlist
   describe `varlist', simple
end

cap program drop myprog
program define myprog
   version 10.1
   syntax varlist
   someprog `varlist'
end

sysuse auto, clear
myprog price-turn

Aaron Thomas wrote:
I'm having two problems, and hoping someone can help me with this.

I have a program that takes a varlist in stata 10. (So I type something like:
someprog var1-var99
Then it does something with the data.)

I have another program that takes a varlist, and I want to pass that varlist to the first program so I can then work with the data it gives back.
(so, something like
myprog var1-var99
Now, myprog needs to pass that varlist to someprog )

I can't seem to do this in Stata. I can pass var1-var99 to one program, but writing a program in a way that it can take any varlist and pass it to the next one is invisible to me, I've been crawling the web for four hours now looking for a way to do this. Someone please help me, or tell me where to get the right help. Which is my second problem. Where do I get some information about programming in Stata that makes sense? I program in C/C++, python, lisp, basic, c#, pascal, java, and several scripting languages, and the flat linear interpreted style of Stata is unfamiliar ground for me, I can't find anything readable on it. Thanks.


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

--
Michael I. Lichter, Ph.D. <mlichter@buffalo.edu>
Research Assistant Professor & NRSA Fellow
UB Department of Family Medicine / Primary Care Research Institute
UB Clinical Center, 462 Grider Street, Buffalo, NY 14215
Office: CC 125 / Phone: 716-898-4751 / FAX: 716-898-3536

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