Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: RE: Nested loops?


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: RE: Nested loops?
Date   Tue, 21 Sep 2004 15:36:22 +0100

Better! 

Nick 
n.j.cox@durham.ac.uk 

> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of Edwin Leuven
> Sent: 21 September 2004 15:36
> To: statalist@hsphsun2.harvard.edu
> Subject: Re: st: RE: Nested loops?
> 
> 
> or rather
> 
> local varlist "v1 v2 v3 v4 v5 v6 v7 v8"
> tokenize "`varlist'"
> local nv : word count `varlist'
> forval i = 1/`nv' {
>  	forval j = `=`i'+1'/`nv' {
>  		gen ``i''_``j'' = ``i'' * ``j''
>  	}
> }
> 
> 
> >
> > Nick
> > n.j.cox@durham.ac.uk
> >
> > adiallo5@worldbank.org
> >
> >> I would like to generate the following variables:
> >>
> >> local myvars "v1 v2 v3 v4 v5 v6 v7 v8....etc..."
> >>
> >> for var v2 v3 v4....:                          g X_v1 =  X*v1
> >> for var v3 v4 v5 v6...:                     g X_v2 =  X*v2
> >> for var v4 v5 v6 v7...                      g X_v3 =  X*v3
> >> etc.
> >>
> >> How to do that, if I have a lot of variables involved?
> >
> > *
> > *   For searches and help try:
> > *   http://www.stata.com/support/faqs/res/findit.html
> > *   http://www.stata.com/support/statalist/faq
> > *   http://www.ats.ucla.edu/stat/stata/
> >
> 
> -- 
> Edwin Leuven
> Department of Economics
> University of Amsterdam
> Roetersstraat 11
> 1018 WB Amsterdam
> the Netherlands
> tel: +31 20 525 5241
> fax: +31 20 525 4310
> http://www.fee.uva.nl/scholar/mdw/leuven
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
> 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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