clear clear matrix set matsize 800 set mem 500m cd [your file directory] use [gwar_1952_2025_raw.csv] rename v7 gwar_plus rename (year ) (yearID ) gen teamID =team drop if gametype!="Reg" *** Convert retro team names to Lahman replace teamID = "ML4" if teamID == "MIL" & year<1998 replace teamID = "ML1" if teamID == "MLN" replace teamID = "LAA" if teamID == "ANA" & year>2004 replace teamID = strtrim(teamID) * Correct nonretro/Lahman teamids replace teamID = "ARI" if teamID == "AZ" replace teamID = "CHA" if teamID == "CWS" replace teamID = "CHN" if teamID == "CHC" replace teamID = "KCA" if teamID == "KC" replace teamID = "LAN" if teamID == "LAD" replace teamID = "NYA" if teamID == "NYY" replace teamID = "NYN" if teamID == "NYM" replace teamID = "SDN" if teamID == "SD" replace teamID = "SFN" if teamID == "SF" replace teamID = "SLN" if teamID == "STL" replace teamID = "TBA" if teamID == "TB" replace teamID = "WAS" if teamID == "WSH" * year-sensitive: Marlins are FLO in Lahman thru 2011, MIA from 2012. * gridwar uses MIA for all 2008+, so only pre-2012 needs flipping. replace teamID = "FLO" if teamID == "MIA" & yearID <= 2011 merge m:1 yearID teamID using C:\Users\dmk38\Documents\x5\lahaman_team_id_key_2025.dta,nogen drop if year<1952 collapse (sum) gwar gwar_plus,by(yearID teamID team) bys yearID: egen z_gwar=std(gwar) bys yearID: egen z_gwarplus=std(gwar_plus) save [gridwar_team_coded.csv in .dta or alternative]