Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: loops

From   Hawal Shamon <>
To   <>
Subject   st: loops
Date   Wed, 21 Dec 2011 12:10:22 +0100

Dear all!

I have problems in finding the correct syntax for a nested loop.

 have the string variables AB01_01, AB01_02, ..., AB01_30 and like to 
encode and rename them at the same time. Renaming is necessary to get 
rid of the "_" in the variables name. Do the result is supposed to be 
AB0101, AB0102, ..., AB0130.

I tried it with:

local i 1
while `i' <=30 {
foreach var of varlist AB01_01-AB01_30 {
encode `var', gen(AB01`i')

and received the following error message:
.AB011 already defined

I understand the problem. However, I have no clue how to avoid this problem.

Can anyone help?

Thanks in advance!


*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index