clear * cap log close set more off set mem 500m set matsize 5000 *cd "FILL OUT YOUR DIRECTORY" log using "step4characteristics.log", replace use mlbmaster.dta, replace sum spellid op_spellid local maxspell=r(max) drop if lagtotalpay==. drop if op_lagtotalpay==. egen helpmatchup=group(year teamid op_teamid) bysort game_id: egen helpmatchup2=min(helpmatchup) egen matchup=group(helpmatchup2) drop helpmatchup helpmatchup2 sum *************************VARIABLE GENERATION**************************** *run difference gen rundif=sc-op_sc *home advantage: gen op_home=1-home *log of wages: gen ltotalpay=log(totalpay) gen op_ltotalpay=log(op_totalpay) gen lpitcherpay=log(pitchersalary) gen op_lpitcherpay=log(op_pitchersalary) gen lagltotalpay=log(lagtotalpay) gen op_lagltotalpay=log(op_lagtotalpay) gen lstdevpay=log(stdevpay) gen op_lstdevpay=log(op_stdevpay) gen laglstdevpay=log(lagstdevpay) gen op_laglstdevpay=log(op_lagstdevpay) *log of market characteristics gen lpop=log(cmsapop) gen op_lpop=log(op_cmsapop) gen lteamscmsa=1 if teamscmsa==2 gen op_lteamscmsa=1 if op_teamscmsa==2 replace lteamscmsa=0 if lteamscmsa==. replace op_lteamscmsa=0 if op_lteamscmsa==. gen lstadcap=log(stadcap) gen op_lstadcap=log(op_stadcap) gen lstadcaphome=lstadcap*home gen op_lstadcaphome=op_lstadcap*op_home gen lattendance=log(attendance) gen latthome=lattendance*home gen op_latthome=lattendance*op_home gen lstadage=log(stadage) gen op_lstadage=log(op_stadage) gen lmarketten=log(marketten) gen op_lmarketten=log(op_marketten) gen lhomevalue=log(homevalue) gen op_lhomevalue=log(op_homevalue) *allow different wage effect in play off: gen ltotalpayplayoff=ltotalpay*playoff gen op_ltotalpayplayoff=op_ltotalpay*playoff *make a league indicator egen leagueid=group(league) egen op_leagueid=group(op_league) ******************************************COACH AND GM CHARACTERISTICS********************************** *obs bysort coachid: egen coachobs=count(coachid) bysort gmid: egen gmobs=count(gmid) *age gm: replace gmdob=1 if gmdob==. replace op_gmdob=1 if op_gmdob==. replace gmmob=1 if gmmob==. replace op_gmmob=1 if op_gmmob==. gen gmbirthdate=mdy(gmmob,gmdob,gmyob) gen op_gmbirthdate=mdy(op_gmmob,op_gmdob,op_gmyob) gen gmage=date-gmbirthdate gen op_gmage=date-op_gmbirthdate gen gmlage=log(gmage) gen op_gmlage=log(op_gmage) gen gmagesq=gmage^2 gen op_gmagesq=op_gmage^2 gen gmlagesq=log(gmage)^2 gen op_gmlagesq=log(op_gmage)^2 *exp gm: gen gmcareerstartmonth=1 gen op_gmcareerstartmonth=1 gen gmcareerstartday=1 gen op_gmcareerstartday=1 gen gmcareerstartdate=mdy(gmcareerstartmonth,gmcareerstartday,gmstartfrontoffyear) gen op_gmcareerstartdate=mdy(op_gmcareerstartmonth,op_gmcareerstartday,op_gmstartfrontoffyear) gen gmexp=date-gmcareerstartdate+1 gen op_gmexp=date-op_gmcareerstartdate+1 gen gmlexp=log(gmexp) gen op_gmlexp=log(op_gmexp) gen gmexpsq=gmexp^2 gen op_gmexpsq=op_gmexp^2 gen gmlexpsq=log(gmexp)^2 gen op_gmlexpsq=log(op_gmexp)^2 *race gm gen gmminority=1 if gmafro==1 replace gmminority=1 if gmhispanic==1 replace gmminority=0 if gmminority==. gen op_gmminority=1 if op_gmafro==1 replace op_gmminority=1 if op_gmhispanic==1 replace op_gmminority=0 if op_gmminority==. *position gm drop gmplayposition op_gmplayposition gen gmplayposition=0 replace gmplayposition=1 if gmcatcher==1 replace gmplayposition=2 if gm1b==1 replace gmplayposition=2 if gm2b==1 replace gmplayposition=2 if gm3b==1 replace gmplayposition=3 if gmof==1 replace gmplayposition=4 if gmss==1 replace gmplayposition=5 if gmp==1 gen op_gmplayposition=0 replace op_gmplayposition=1 if op_gmcatcher==1 replace op_gmplayposition=2 if op_gm1b==1 replace op_gmplayposition=2 if op_gm2b==1 replace op_gmplayposition=2 if op_gm3b==1 replace op_gmplayposition=3 if op_gmof==1 replace op_gmplayposition=4 if op_gmss==1 replace op_gmplayposition=5 if op_gmp==1 *player level gm gen gmplaylevel=0 replace gmplaylevel=1 if gmproplay==1 replace gmplaylevel=2 if gmplaymlb==1 replace gmplaylevel=3 if gmallstar==1 gen op_gmplaylevel=0 replace op_gmplaylevel=1 if op_gmproplay==1 replace op_gmplaylevel=2 if op_gmplaymlb==1 replace op_gmplaylevel=3 if op_gmallstar==1 *gm education gen gmeducation=0 replace gmeducation=1 if gmcolatt==1 replace gmeducation=2 if gmcolgrad==1 replace gmeducation=3 if gmcoltop100==1 gen op_gmeducation=0 replace op_gmeducation=1 if op_gmcolatt==1 replace op_gmeducation=2 if op_gmcolgrad==1 replace op_gmeducation=3 if op_gmcoltop100==1 *age coach gen coachbirthdate=mdy(coachmob,coachdob,coachyob) gen op_coachbirthdate=mdy(op_coachmob,op_coachdob,op_coachyob) gen coachage=date-coachbirthdate gen op_coachage=date-op_coachbirthdate gen coachlage=log(coachage) gen op_coachlage=log(op_coachage) gen coachagesq=coachage^2 gen op_coachagesq=op_coachage^2 gen coachlagesq=log(coachage)^2 gen op_coachlagesq=log(op_coachage)^2 *exp coach gen coachcareerstartdate=mdy(coachcareerstartmonth,coachcareerstartday,coachcareerstartyear) gen op_coachcareerstartdate=mdy(op_coachcareerstartmonth,op_coachcareerstartday,op_coachcareerstartyear) gen coachexp=date-coachcareerstartdate+1 gen op_coachexp=date-op_coachcareerstartdate+1 gen coachlexp=log(coachexp) gen op_coachlexp=log(op_coachexp) gen coachexpsq=coachexp^2 gen op_coachexpsq=op_coachexp^2 gen coachlexpsq=log(coachexp)^2 gen op_coachlexpsq=log(op_coachexp)^2 gen coachlmlbplayexp=log(gmmlbexp) gen op_coachlmlbplayexp=log(op_gmmlbexp) *race coach gen coachminority=1 if coachafro==1 replace coachminority=1 if coachhispanic==1 replace coachminority=0 if coachminority==. gen op_coachminority=1 if op_coachafro==1 replace op_coachminority=1 if op_coachhispanic==1 replace op_coachminority=0 if op_coachminority==. *position coach drop coachplayposition op_coachplayposition gen coachplayposition=0 replace coachplayposition=1 if coachcatcher==1 replace coachplayposition=2 if coach1b==1 replace coachplayposition=2 if coach2b==1 replace coachplayposition=2 if coach3b==1 replace coachplayposition=3 if coachof==1 replace coachplayposition=4 if coachss==1 replace coachplayposition=5 if coachp==1 gen op_coachplayposition=0 replace op_coachplayposition=1 if op_coachcatcher==1 replace op_coachplayposition=2 if op_coach1b==1 replace op_coachplayposition=2 if op_coach2b==1 replace op_coachplayposition=2 if op_coach3b==1 replace op_coachplayposition=3 if op_coachof==1 replace op_coachplayposition=4 if op_coachss==1 replace op_coachplayposition=5 if op_coachp==1 *player level coach gen coachplaylevel=0 replace coachplaylevel=1 if coachproplay==1 replace coachplaylevel=2 if coachplaymlb==1 replace coachplaylevel=3 if coachallstar==1 gen op_coachplaylevel=0 replace op_coachplaylevel=1 if op_coachproplay==1 replace op_coachplaylevel=2 if op_coachplaymlb==1 replace op_coachplaylevel=3 if op_coachallstar==1 *coach education gen coacheducation=0 replace coacheducation=1 if coachcolatt==1 replace coacheducation=2 if coachcolgrad==1 gen op_coacheducation=0 replace op_coacheducation=1 if op_coachcolatt==1 replace op_coacheducation=2 if op_coachcolgrad==1 ****************************MATCHING QUALITY************************************ **observables gen gmmatcheducation=gmeducation replace gmmatcheducation=2 if gmmatcheducation==3 gen matcheducation=abs(gmmatcheducation-coacheducation) gen matchplaylevel=abs(gmplaylevel-coachplaylevel) gen matchage=log(abs(gmage-coachage)) gen matchexp=log(abs(gmexp-coachexp)) gen op_gmmatcheducation=op_gmeducation replace op_gmmatcheducation=2 if op_gmmatcheducation==3 gen op_matcheducation=abs(op_gmmatcheducation-op_coacheducation) gen op_matchplaylevel=abs(op_gmplaylevel-op_coachplaylevel) gen op_matchage=log(abs(op_gmage-op_coachage)) gen op_matchexp=log(abs(op_gmexp-op_coachexp)) **signed match gen posmatchedu = (gmmatcheducation>coacheducation) gen negmatchedu = (gmmatcheducationcoachplaylevel) gen negmatchplay = (gmplaylevelop_coacheducation) gen op_negmatchedu = (op_gmmatcheducationop_coachplaylevel) gen op_negmatchplay = (op_gmplaylevel