| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: foreach-question
At 05:36 AM 4/21/2006, Johannes Geyer wrote:
Dear Statalist,
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?
I simulated your problem via the following:
clear
set obs 100
corr2data netto pbleib pbbil01 pbbil02 pbbil03 phrf famstd stell pnat
nace psbil hhgr eigen kzahl
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' {
gen `x'`z' = `z'
rename `x'`z' `z'`y'
}
local y = `y' + 1
}
As far as I can tell, it worked fine. Are you sure that lkzahl,
mkzahl, etc. exist?
-------------------------------------------
Richard Williams, Notre Dame Dept of Sociology
OFFICE: (574)631-6668, (574)631-6463
FAX: (574)288-4373
HOME: (574)289-5227
EMAIL: [email protected]
WWW (personal): http://www.nd.edu/~rwilliam
WWW (department): http://www.nd.edu/~soc
*
* 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/