Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: does stata create an index that can be used in loops?


From   Maarten buis <maartenbuis@yahoo.co.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: does stata create an index that can be used in loops?
Date   Thu, 8 Feb 2007 08:02:52 +0000 (GMT)

--- Brent Fulton <fultonb@berkeley.edu> wrote:
> I would like the following variables to be created:
> var1_county, var2_county, var3_county
> 
> I did the following:
> 
> local a "var1 var2 var3"
> foreach x of local a{
> local b "`b' `x'"
> }
> *the loop above results in the following: local b "var1_zip var2_zip
> var3_zip"

I assume that the line:
local b "`b' `x'"
actually read:
local b "`b' `x'_zip"

> 
> sort county
> foreach x of local b{
> by county: egen `x'_county=total(`x')
> }


I would do this in one loop:
sort county
forvalues i = 1/3 {
    by county: egen var`i'_county = total(var`i'zip)
}


-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


		
___________________________________________________________ 
Now you can scan emails quickly with a reading pane. Get the new Yahoo! Mail. http://uk.docs.yahoo.com/nowyoucan.html
*
*   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