def add_offside_variable(df_events):
    """
    This function removes the offside events in the Wyscout event data and adds
    sets offside to 1 for the previous event (if this was a passing event)

    Args:
    df_events (pd.DataFrame): Wyscout event dataframe

    Returns:
    pd.DataFrame: Wyscout event dataframe with an extra column 'offside'
    """

    # Create a new column for the offside variable
    df_events["offside"] = 0

    # Shift events dataframe by one timestep
    df_events1 = df_events.shift(-1)

    # Select offside passes
    selector_offside = (df_events1["type_id"] == 6) & (df_events["type_id"] == 8)

    # Set variable 'offside' to 1 for all offside passes
    df_events.loc[selector_offside, "offside"] = 1

    # Remove offside events
    df_events = df_events[df_events["type_id"] != 6]

    # Reset index
    df_events = df_events.reset_index(drop=True)

    return df_events