Hello,
I am trying to generate a variable (timecode) that will capture when a different variable (hgc) has reached above a certain value (in this case, 12), as represented by negative numbers in the time periods leading up to that time, 0 when that occurs, and positive numbers representing time periods after the event. For example, -3 -2 -1 0 1 2 3, with 0 representing the period when the variable hgc reaches 12.
I am dealing with panel data, roughly 4000 individuals, with approximately 80,000 observations. For simplicity's sake, I am toying with only the individual's id, year, and highest grade completed (hgc), with timecode being the name of the new variable I wish to generate. I have (correctly, I hope) provided some sample data via dataex below.
The issue I am struggling to overcome is that the time in which the variable hgc surpasses a certain value--in this case, 12--does not occur in the same year for every individual. This has proven too much for my limited stata skills and I am hoping for some guidance from a more experienced user.
Best,
Joseph
I am trying to generate a variable (timecode) that will capture when a different variable (hgc) has reached above a certain value (in this case, 12), as represented by negative numbers in the time periods leading up to that time, 0 when that occurs, and positive numbers representing time periods after the event. For example, -3 -2 -1 0 1 2 3, with 0 representing the period when the variable hgc reaches 12.
I am dealing with panel data, roughly 4000 individuals, with approximately 80,000 observations. For simplicity's sake, I am toying with only the individual's id, year, and highest grade completed (hgc), with timecode being the name of the new variable I wish to generate. I have (correctly, I hope) provided some sample data via dataex below.
The issue I am struggling to overcome is that the time in which the variable hgc surpasses a certain value--in this case, 12--does not occur in the same year for every individual. This has proven too much for my limited stata skills and I am hoping for some guidance from a more experienced user.
Best,
Joseph
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte(id hgc) int year float timecode 1 12 1981 . 1 12 1982 . 1 12 1983 . 1 12 1984 . 1 12 1985 . 1 12 1986 . 1 12 1987 . 1 12 1988 . 1 12 1989 . 1 12 1990 . 1 12 1991 . 1 12 1992 . 1 13 1996 . 1 13 1998 . 1 13 2000 . 1 13 2002 . 1 13 2004 . 1 13 2006 . 1 13 2008 . 1 13 2010 . 1 13 2012 . 2 11 1981 . 2 12 1982 . 2 12 1983 . 2 12 1984 . 2 12 1985 . 2 12 1986 . 2 12 1987 . 2 12 1988 . 2 12 1989 . 2 13 1990 . 2 13 1991 . 2 13 1992 . 2 13 1996 . 2 13 1998 . 2 13 2000 . 2 13 2002 . 2 13 2004 . 2 13 2006 . 2 13 2008 . 2 13 2010 . 2 13 2012 . 3 11 1981 . 3 11 1982 . 3 12 1983 . 3 12 1984 . 3 12 1985 . 3 12 1986 . 3 12 1987 . 3 12 1988 . 3 12 1989 . 3 12 1990 . 3 12 1991 . 3 12 1992 . 3 12 1996 . 3 12 1998 . 3 12 2000 . 3 12 2002 . 3 12 2004 . 3 12 2006 . 3 12 2008 . 3 12 2010 . 3 12 2012 . 4 11 1981 . 4 11 1982 . 4 11 1983 . 4 12 1984 . 4 12 1985 . 4 12 1986 . 4 12 1987 . 4 12 1988 . 4 12 1989 . 4 12 1990 . 4 12 1991 . 4 12 1992 . 4 12 1996 . 4 12 1998 . 4 13 2000 . 4 13 2002 . 4 13 2004 . 4 13 2006 . 4 14 2008 . 4 15 2010 . 4 16 2012 . end
Comment