Bookmark and Share

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]

Re: st: foreach loop over all variables


From   Tim Wade <wadetj@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: foreach loop over all variables
Date   Sat, 25 Feb 2012 14:14:25 -0500

Help -varlist- provides the following: "Many commands understand the
keyword _all to mean all variables"

so this also works:

sysuse auto.dta
foreach var of varlist _all {
summ `var'
}

Tim



On Thu, Feb 23, 2012 at 4:31 AM, Seliger  Florian <seliger@kof.ethz.ch> wrote:
> Dear Statalist,
>
> Maybe that's a silly question, but Google didn't give any answers:
>
> I want to create a loop with foreach over ALL variables in a dataset,
>
> foreach ALL VARIABLES {
> ...
> }
>
> It is not possible to write
>
> foreach var1-var100
>
> because the number and names of the variables vary from dataset to dataset and the do-file has to work for any dataset without making any changes.
>
>
> Thanks a lot.
>
>
> Best wishes,
>
>
> __________
>
> Florian Seliger
> Researcher
>
> ETH Zurich
> KOF Swiss Economic Institute
> WEH C 5
> Weinbergstrasse 35
> 8092 Zurich, Switzerland
>
> seliger@kof.ethz.ch
> www.kof.ethz.ch
>
> +41 44 632 37 17 phone
> +41 44 632 12 18 fax
>
> *
> *   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/

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