Statalist The Stata Listserver


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

Re: st: foreach-question


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: foreach-question
Date   Fri, 21 Apr 2006 12:04:30 +0100 (BST)

There doesn't appear anything wrong with your
�foreach- command, however a local can contain 
only a limited number of characters, and your 
list of variables probably contains too many 
characters. All extra characters are ignored, 
so apparently the maximum was reached with 
kzahl and was thus ignored. One way to prevent 
that is to replace the line 

- foreach z in `vars' {-
with
�foreach z of varlist netto � kzahl {-

(if the variables netto till kzahl are all next 
to each other in the dataset). For more 
information see �help foreach- and �help varlist-.
HTH,
Maarten

--- Johannes Geyer <[email protected]> wrote:
> it seems to me that I did not understand the Syntax of "foreach", I typed
> the code below to produce a panel data set for which I had to rename some
> variables and added an index(1995,1996,1997,...,2004) as suffix. The loop
> works perfectly well until it reaches the last variable "kzahl". I do not
> know why but the last variable is not processed in the loop. Has anyone an
> idea where I made a mistake?
> 
> Thanks for your help,
> Johannes
> 
> local wave = "l m n o p q r s t u"
> local vars = "netto pbleib pbbil01 pbbil02 pbbil03 phrf famstd stell pnat
> nace psbil hhgr eigen kzahl"
> local y    = 1995
> 
> foreach x in `wave' {
> 
>    foreach z in `vars' {
>       rename `x'`z' `z'`y'
>    }
> 
>    local y = `y' + 1
> }


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

visiting adress:
Buitenveldertselaan 3 (Metropolitan), room Z214

+31 20 5986715

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


		
___________________________________________________________ 
Switch an email account to Yahoo! Mail, you could win FIFA World Cup tickets. http://uk.mail.yahoo.com
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index