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: double loops with "forvalues"

From   xueliansharon <>
Subject   st: double loops with "forvalues"
Date   Sat, 16 Jun 2012 15:11:07 -0700 (PDT)

Dear all,

I want to do a double looping, the commands are as follows: 

forvalues i=1944/1955 {
	forvalues j=2106/2117 {
		gen fa`i'=f`i' if fr==1
		replace fa`i'=f`j' if fr==0

The purpose is to generate 12 new variables (fa1944, fa1945, fa1946, ...,
fa1955) with the following characteristics: 
fa1944=f1944 if fr==1; fa1944=f2106 if fr==0
fa1945=f1945 if fr==1; fa1945=f2107 if fr==0
fa1946=f1946 if fr==1; fa1946=f2108 if fr==0
fa1955=f1955 if fr==1; fa1955=f2117 if fr==0

However, whenever I run this program, Stata always returns an error message
as "fa1944 already defined". Could you please tell me how I should modify
the program?

Thank you very much!


View this message in context:
Sent from the Statalist mailing list archive at
*   For searches and help try:

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