Dear All, Suppose that I have the following data
For each `id', there are (a pair of) `name's for each `year'. The purpose is to construct `number1' and `number2'. For id=2, starting from year=1992, two names a and b appear in the first time. As a result, number1=1 and number2=1. In the next year (1993), both a and b appear the second time, and thus number1=2 and number2=2. In the third year (1994), c appears in the first time, number1=1 but b appears in the third time, number2=3. Any suggestions? Thanks.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte id int year str3 name byte(number1 number2) 2 1992 "a,b" 1 1 2 1993 "b,a" 2 2 2 1994 "c,b" 1 3 2 1995 "a,b" 1 4 2 1996 "d,e" 1 1 2 1997 "d,e" 2 2 2 1998 "d,e" 3 3 2 1999 "d,e" 4 4 2 2000 "d,e" 5 5 2 2001 "f,g" 1 1 2 2002 "f,h" 2 1 2 2003 "h,g" 2 1 2 2004 "h,i" 3 1 2 2005 "j,i" 1 2 2 2006 "j,i" 2 3 2 2007 "" . . 2 2008 "i,l" 1 1 2 2009 "m,j" 1 1 2 2010 "j,n" 2 1 2 2011 "j,o" 3 1 2 2012 "j,o" 4 2 2 2013 "j,o" 5 3 2 2014 "p,q" 1 1 2 2015 "p,q" 2 2 end
Comment