Dear statalister,
I am facing a difficult problem for me to solve on stata.
I have data on footballer and football clubs as follow:
FootBaller id / Club id / Date
1 / 1 / 1995
1 / 3 / 1999
1 / 6 / 2002
2 / 3 / 1994
2 / 6 / 2005
etc..
Date is actually the year when the footballer joined a new club. My goal is to compute for each entry the number of different clubs attended in the last 5 years (for exemple here, value for _n = 1 is 1, 2 for _n = 2, 2 for _n = 2 etc...
One solution would be looping over each obs and counting, unfortunatly I have more than a million observations and this would take forever...
Thanks a lot for suggestions
Totonio
I am facing a difficult problem for me to solve on stata.
I have data on footballer and football clubs as follow:
FootBaller id / Club id / Date
1 / 1 / 1995
1 / 3 / 1999
1 / 6 / 2002
2 / 3 / 1994
2 / 6 / 2005
etc..
Date is actually the year when the footballer joined a new club. My goal is to compute for each entry the number of different clubs attended in the last 5 years (for exemple here, value for _n = 1 is 1, 2 for _n = 2, 2 for _n = 2 etc...
One solution would be looping over each obs and counting, unfortunatly I have more than a million observations and this would take forever...
Thanks a lot for suggestions
Totonio

, I'll venture a guess that what he wants Iin each observation is the number of clubs that the footballer attended in the five years preceding Date. I'm feeling less telepathic as to whether, say, for 1995, this includes 1990 or only goes back through 1991. In the code below I assume that 1990 would be included, but it is easy enough to change it to the other way if I got that wrong.
Comment