Hi,
I have data on soccer game results. I want to generate variable that will
reflect how a team played in the last 2 games: win_streak=sum of points in
the last 2 games.
Simple example, with 4 teams and 3 rounds:
Round Home_team Away_team Points_home_team Points_away_team
1 A B 3
0
1 C D 1
1
2 B D 0
3
2 A C 1
1
3 D A 3
0
3 B C 1
1
Then I want to create the variable:
Round Team Win_streak
3 A 4
3 B 0
3 C 2
3 D 4
The problem is that in the data a team could be in column 2 or column 3
depending on playing home or away. Also, when I add points I should check
if I look at 4th or 5th column. Therefore, I can not just use: by sort team
(round): egen win_streak= points[_n-1]+points[_n-2].
Can you suggest how to deal with my ptoblem?
Thanks,
Oleksandr.
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/