added codes to sort and get the latest year data for each country after extracting gender