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 } }
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--
0 Response to Replacing a variable in a longitudinal dataset based on a criteria
Post a Comment