Dear Statalist users,

I have a longitudinal file in the long format. Please see a part of the variables generated by dataex below. I am trying to look at each xwaveid, and see if I have both for the wave=2010 treatgroup==1, if this is the case I am trying to make for all waves of that xwaveid the treatgroup=1 by replacing it. I have tried different version of the below code, but gotten each time a syntax or command error.

Code:
gen controlgroupsum=0
foreach wave of 2006 2007 2008 2009 2010 2011 2012 2013 2014 {
if controlgroup > 0 {
replace controlgroupsum = controlgroupsum + 1
}
}
This way I wanted to look if controlgroupsum>0, then make controlgroup=1 for all waves of each xwaveid. To sum up, I want to make all observations belong either to the controlgroup or treatment group. But I get a syntax error every time. And I feel like I cannot explain my intentions to STATA the way I coded it (which didnt work anyway). Can anyone help me on what I might be doing wrong? Thank you very much for all the help in advance..

Code:
clear
input long xwaveid float(wave treatgroup controlgroup)
100018 2006 0 1
100018 2007 0 1
100018 2008 0 1
100018 2009 0 1
100018 2010 0 1
100018 2011 0 1
100018 2012 0 1
100018 2013 0 1
100018 2014 0 1
100019 2006 0 1
100019 2007 0 1
100019 2008 0 1
100019 2009 0 1
100019 2010 0 1
100019 2011 0 1
100019 2012 0 1
100019 2013 0 1
100019 2014 0 1
100100 2006 0 0
100100 2007 0 0
100100 2008 0 0
100100 2009 1 0
100100 2010 1 0
100100 2011 1 0
100100 2012 1 0
100100 2013 1 0
100100 2014 1 0
--more--