Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: how to generate variable for non-standard data

From   "Oleksandr Talavera, EUV" <>
Subject   Re: st: how to generate variable for non-standard data
Date   Sun, 16 Nov 2003 13:46:06 +0100

Try the following:
* soccer.dta has your data
use soccer, clear
keep round h_team h_points
rename h_team team
rename h_points points
* additional dataset  soccerH that contains home team data
save soccerH, replace
use soccer, clear
keep round a_team a_points
rename a_team team
rename a_points points
append using soccerH
egen teams=group(team)
tsset teams round
g win_streak = L.points + L2.points
sort round team
Oleksandr Shepotylo wrote:


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
1                      C                    D                       1
2                      B                    D                       0
2                      A                    C                       1
3                      D                    A                       3
3                      B                    C                       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?



*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2023 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index