I'm looking to run a loop to create a binary variable that identifies if two statements are true. In this case, I'm looking to identify if the defensive team is also the home team (ie: the stadium is the defensive team's home stadium).
Offensive Team       Defensive Team         Stadium                   
Dodgers              Yankees                Yankee Stadium
Red Sox              Dodgers                Dodger Stadium
Cubs                 Astros                 Wrigley Field
Yankees              Dodgers.               Yankee Stadium
Thus, I want my final dataframe to look like this.
Offensive Team       Defensive Team         Stadium                Defense_Home          
Dodgers              Yankees                Yankee Stadium         1
Red Sox              Dodgers                Dodger Stadium         1
Cubs                 Astros                 Wrigley Field          0
Yankees              Dodgers                Yankee Stadium         0
I understand of course that I will have to write out a full list of stadiums and which teams they correspond to--just looking for a template for how to code it in. I also understand that this is a pretty beginner-level question, as I am not that good at writing loops in R--doing the same thing in STATA would be much easier for me. Still learning.
Thanks in advance!
 
    