Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

st: forval query

From   "Mirnezami, Oliver" <>
To   "" <>
Subject   st: forval query
Date   Fri, 5 Apr 2013 13:32:12 +0000


I'm having some difficulty in using forval and foreach commands and was hoping for some help with the syntax please. 

Previously i've been renaming variables manually en masse using the following code:

rename  r2mobila mobila_1994
rename  r3mobila mobila_1996
rename  r4mobila mobila_1998
rename  r10mobila mobila_2010

i.e. '2' corresponds with '1994', '3' with '1996' etc.  

I've tried using the following command but i get an r(111) error:

forval i = 2/10 {
forval j = 1994/2010 {
foreach k in r`i'mobila {
rename `k' mobila_`j' 

I don't think I've managed to link '2' with '1994' and '3' with '1996' properly.

I have to do this technique for many variables and so used this case as an example. 

Any advice would be much appreciated. 

Kind regards


*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index