def add_data_for_name(name_data, year, rank, name):
    """
    Adds the given year and rank to the associated name in the name_data dict.
    :param name_data: dict, dict holding name data
    :param year: str, the year of the data entry to add
    :param rank: str, the rank of the data entry to add
    :param name: str, the name of the data entry to add
    :return: name_data: dict, dict holding name data
    """
    # Add name to dict
    if name not in name_data:
        name_data[name] = {}
        name_data[name][year] = rank
    else:
        # Add new information to each name
        if year in name_data[name]:
            if int(name_data[name][year]) < int(rank):
                return name_data
            else:
                name_data[name][year] = rank
        else:
            name_data[name][year] = rank

    return name_data