With Gender in column B, create a new column for Count.
With the first gender in B2, enter the following in row 2 of
the Count column:
=COUNTIF($B$1:B1,B2)+1
Copy the formula down to the last row of data
Select a cell in the table
Choose Data>Sort
Sort by Count, then by Gender