clear
set more off
set mem 40m
#delimit ;

insheet using "http://dss.ucsd.edu/~ssaiegh/Soccer_Replication/Wb_codes.csv";
rename id nation;
sort nation;
save Wb_codes, replace;
clear;

use http://dss.ucsd.edu/~ssaiegh/Soccer_Replication/soccer_data.dta;


drop num_country;

drop if contract==.;

/* Get the number of players per country */;

egen num_country = count(player_id)
if (italian | champions |  english  | french | german | spanish), by(nationality);


/* FIGURE 4 */;

keep if oecd==0;
drop if nation==23;
drop if nation==52;
drop if nation==54;
drop if nation==78;
drop if nation==101;

sort nation;
merge nation using Wb_codes;


collapse yellow_card
	civwar nation num_country
age games_start games_sub
goalie defender forward midfield
goals ln_contract italian champions english french german spanish
africa asia lac east_europe oecd
if (italian | champions |  english | french | german | spanish) & (num_country>=5),
	by(wb_code);

regress yellow_card
age games_start games_sub
/*goalie*/ defender forward midfield
goals ln_contract
italian champions /*english*/ french german spanish
africa asia lac east_europe;

predict yellowhat;

generate yellow_res=yellow_card-yellowhat;

regress civwar
age games_start games_sub
/*goalie*/ defender forward midfield
goals ln_contract
italian champions /*english*/ french german spanish
africa asia lac east_europe;

predict warhat;

generate war_res=civwar-warhat;


label var yellow_res "Average Yellow Cards Per Player-Season (Residuals)";

label var war_res "Years of Civil War since 1980 (Residuals)";

twoway scatter yellow_res war_res [w=num_country], ylabel(-1 (.25) 1) xlabel(-6 (4) 6)
msymbol(Oh) legend(off)
|| lfit yellow_res war_res
|| scatter yellow_res war_res, ylabel(-1 (.25) 1) xlabel(-6 (4) 6)
msymbol(none) mlabel(wb_code)
note("Area of symbol proportional to the country's number of players in these competitions");