Hello everyone,
I am working with a dataset where each observation is a meeting that occurred at some point in time by a specific group. Hence, I have many groups that meet irregularly over time. I wish to create a counter variable that measures the number of times a particular group met in the previous, say, five years (thus excluding the "current" meeting). I must admit that I have no idea how to measure that.
Here is an example of what I am working with (the real dataset has 50 groups that met for a total of 1500 times). I basically want to generate the variable nbOcc by syntax rather than by hand.
So, in this example, at line 1, group one is meeting for the first time, so there is no meeting in the previous 5 years. At line 3, group one has met twice in the previous five years, etc.
I don't normally ask the Statalist for syntax without trying anything myself first, but I am truly confused as to how this would go. I think I need to sort by ID and then date (which is why I included edate and emonth, although emonth might be sufficient), and create a loop of some sort, but other than that I really don't know where I am going...
Any help would be greatly appreciated!
JP Gauvin
I am working with a dataset where each observation is a meeting that occurred at some point in time by a specific group. Hence, I have many groups that meet irregularly over time. I wish to create a counter variable that measures the number of times a particular group met in the previous, say, five years (thus excluding the "current" meeting). I must admit that I have no idea how to measure that.
Here is an example of what I am working with (the real dataset has 50 groups that met for a total of 1500 times). I basically want to generate the variable nbOcc by syntax rather than by hand.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte groupID int year byte(month day) float(edate emonth) byte nbOcc 1 1990 1 20 10977 360 0 1 1990 5 12 11089 364 1 1 1993 4 15 12158 399 2 1 2000 7 2 14793 486 0 2 1990 2 16 11004 361 0 2 1990 3 23 11039 362 1 2 1990 8 25 11194 367 2 2 1991 10 12 11607 381 3 2 1999 2 10 14285 469 0 3 1992 1 11 11698 384 0 3 1993 3 5 12117 398 1 3 1994 5 6 12544 412 2 3 1995 2 13 12827 421 3 3 1996 1 16 13164 432 4 end
So, in this example, at line 1, group one is meeting for the first time, so there is no meeting in the previous 5 years. At line 3, group one has met twice in the previous five years, etc.
I don't normally ask the Statalist for syntax without trying anything myself first, but I am truly confused as to how this would go. I think I need to sort by ID and then date (which is why I included edate and emonth, although emonth might be sufficient), and create a loop of some sort, but other than that I really don't know where I am going...
Any help would be greatly appreciated!
JP Gauvin
Comment