clear clear matrix set matsize 800 set mem 500m cd [your directory partition that has data files] ******** *Load the efip, FG, and BBR team prs measures ********* use [efip_bbr_fg_prs_measures.csv as .dta] ******* * add team fielding-runs saved data ******* merge m:1 teamID yearID using [fielding_rs.csv], nogen ************************** *create per ip variables ************************** gen rpip=RA // team runs-allowed per ip bys yearID: egen z_rpip=std(rpip) gen efiprs_ip=efip_prs/ip gen bbrar_ip=bbr_rar/ip gen fgrar_ip=fg_rar/ip ************************ *season standardization ************************ bysort yearID: egen z_eprsip=std(efiprs_ip) bysort yearID: egen z_fruns=std(f_runs) bysort yearID: egen z_fgrarip=std(fgrar_ip) bysort yearID: egen z_bbrarip=std(bbrar_ip) ***************************** * 1900-2025 regression models ***************************** regress z_rpip z_eprsip z_fruns [aweight=ip] regress z_rpip z_fgrarip z_fruns [aweight=ip] regress z_rpip z_bbrarip z_fruns [aweight=ip] regress z_rpip z_bbraaip z_fruns [aweight=ip] regress z_rpip z_fruns [aweight=ip] ***************************************************** * multi-season regression models ***************************************************** * calculate incremental R^2s gen Rbase = . gen Ri_bbr = . gen Ri_fg = . gen Ri_efip= . foreach yr of numlist 1900/2025 { // Run the regression with base only for the current year regress rpip f_runs if year == `yr' // Store R2 from the first model for the current year local r2_1 = e(r2) replace Rbase = `r2_1' if year == `yr' // Run the regression with base and fg_rar for the current year regress rpip f_runs fgrar_ip if year == `yr' // Store incremental FG R2 for the current year local r2_2 = e(r2) replace Ri_fg = `r2_2'-Rbase if year == `yr' // Run the regression with base and bbr for the current year regress rpip f_runs bbrar_ip if year == `yr' // Store incemental BBR R2 the current year local r2_3 = e(r2) replace Ri_bbr = `r2_3'-Rbase if year == `yr' // Run the regression with base & efip for the current year regress rpip f_runs efiprs_ip if year == `yr' // Store incemental efip R2 from the third model for the current year local r2_4 = e(r2) replace Ri_efip = `r2_4'-Rbase if year == `yr' di `yr' } preserve collapse (mean) Rbase Ri_bbr Ri_fg Ri_efip,by(yearID) drop if year ==2020 * Create cumulative variables for ribbon placement gen cum_base = Rbase*100 gen cum_fg = (cum_base) + Ri_fg*100 gen cum_bbr = (cum_base) + Ri_bbr*100 gen cum_efip = (cum_base) + Ri_efip*100 * Smooth the data for each cumulative variable foreach lname in base fg bbr efip { lpoly cum_`lname' year,bw(2) gen(smooth_`lname') at(year) } * Create a variable for the lower bound gen zero = 0 twoway /// rarea smooth_base zero yearID, color(gs12%60) alcolor(gs12) || /// Smoothed Base rarea smooth_bbr smooth_base yearID, color(blue%30) alcolor(blue%100) || /// Smoothed Increment rarea smooth_fg smooth_base yearID, color(green%30) alcolor(green%100) || /// rarea smooth_efip smooth_base yearID, color(red%30) alcolor(red%100) || /// Smoothed Increment , legend(off) /// title(" ") /// xlabel(1900(10)2025, labsize(large) nogrid angle(45)format(%ty)) /// ylabel(0(25)100, labsize(large) nogrid angle(0)) /// ytitle("") /// xtitle("") restore