I'm putting together an NBA Dataset for each season that includes data on the outcome of each game of the season.
Each game has 2 observations (from the perspective of each team) and both observations share the same Unique ID.
I have recorded the Win Percentage (# of Wins/Games Played) for each team at the time the game was played.
However, in order to complete my dataset I need to create a new variable for the Opponent's Win Percentage.
The following is an small example of what the dataset looks like for two different games i.e. Boston vs Philadelphia and Miami vs Philadelphia (with only the relevant variables):
Team | TeamID | UniqueID | WinPct | OWinPct |
Boston Celtics | 1610612738 | 100 | 0.5 | |
Philadelphia 76ers | 1610612755 | 100 | 0.75 | |
Miami Heat | 1610612791 | 101 | 0.33 | |
Philadelphia 76ers | 1610612755 | 101 | 0.77 |
To do this, I tried something like the following code:
gen OWinPct==WinPct if UniqueID==UniqueID & TeamID!=TeamID
Obviously to no avail.
I was wondering if there is a way to actually do this?
Apologies for the lack of technical knowledge and clarity, this is my first time using STATA as I am an undergraduate student. Thanks!
0 Response to Issues with Creating a New Variable for Observations with the Same ID
Post a Comment