Dear All, Suppose that I have the data
Code:
clear
input long stkcd int year float dummyvar
10 2002 .
10 2003 0
10 2004 .
10 2005 .
10 2006 .
10 2007 .
10 2008 .
10 2009 0
10 2010 0
10 2012 .
10 2013 0
10 2014 0
11 2000 1
11 2001 1
11 2002 1
11 2004 0
11 2005 0
11 2006 0
11 2007 1
11 2008 1
11 2009 1
11 2010 1
11 2011 1
11 2012 1
11 2013 1
11 2014 1
12 2000 .
12 2001 .
12 2002 1
12 2003 1
12 2004 1
12 2005 1
12 2006 1
12 2007 1
12 2008 1
12 2009 .
12 2010 .
12 2011 1
12 2012 1
12 2013 1
12 2014 1
14 2000 0
14 2001 0
14 2002 1
14 2003 1
14 2004 1
14 2005 1
14 2006 1
14 2007 0
14 2008 0
14 2009 0
14 2010 0
14 2011 0
14 2012 0
14 2013 0
14 2014 0
16 2000 .
16 2001 .
16 2004 0
16 2005 0
16 2006 0
16 2007 0
16 2008 0
16 2009 1
16 2010 1
16 2011 1
16 2012 1
16 2013 0
16 2014 0
17 2004 .
17 2005 0
17 2006 0
17 2007 0
17 2010 0
17 2011 0
17 2012 0
17 2013 0
17 2014 0
18 2002 1
18 2003 1
18 2004 1
18 2005 1
18 2006 1
18 2007 1
18 2008 1
18 2009 1
18 2010 1
18 2011 1
18 2012 1
18 2013 1
18 2014 1
19 2005 1
19 2006 0
19 2007 0
19 2008 1
19 2009 1
19 2010 1
19 2011 0
19 2012 0
19 2013 0
end
For each `stkcd', I'd like to identify sequence 0,0,0,1,1,1 (consecutive 6 year) and create a new variable, say `z', which has value 1 for these 6 years, 0 otherwise. Any suggestion is highly appreciated.