Hi,

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
For example, I want to code the observations so the OWinPct Column corresponding to the Boston Celtics has the 76ers WinPct of 0.75, and the 76ers OWinPct column has the Celtics WinPct of 0.5 (since they share the same UniqueID - 100), and so forth for the rest of the observations.

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!