def generate_counterfactual(df1, df2, group_share, total_population,
    approach, percent=True):
    """Generate a counterfactual variable.

    Given two cities, generate counterfactual distributions for a variable of
    interest by simulating the variable of one city into the spatial
    structure of the other.

    Parameters
    ----------
    df1 : pd.DataFrame
        Pandas dataframe holding data for city 1
    df2 : pd.DataFrame
        Pandas dataframe holding data for city 2
    group_share : str
        The variable (present on both dataframes) for which a counterfactual
        distribution should be generated. This variable should be a fraction
        referring to a share of a certain population group (e.g. a value of 35
        or 0.35 referring to 35% white)
    total_population : str
        The variable (present on both dataframes) representing the total
        population of the area
    approach : str, ["unit_composition", "city_composition", "dual_composition"]
        Which approach to use for generating the counterfactual.
        Options include "unit_composition", "city_composition", or
        "dual_composition"
    percent : bool
        Whether the focal_variable is formatted as a percentage or whole
        number, e.g. 45 vs 0.45. This parameter defines whether the resutls
        should be normalized by dividing by 100

    Returns
    -------
    two pandas.DataFrames
        df1 and df2  with appended columns 'counterfactual_share' and
        'counterfactual_total'

    """
    df1 = df1.copy()
    df2 = df2.copy()
    if approach == 'unit_composition':
        df1['counterfactual_share'] = df1['{variable}'.format(variable=
            group_share)].rank(pct=True).apply(df2['{variable}'.format(
            variable=group_share)].quantile)
        df1['counterfactual_total'] = df1['counterfactual_share'] * df1[
            '{total_pop}'.format(total_pop=total_population)]
        df2['counterfactual_share'] = df2['{variable}'.format(variable=
            group_share)].rank(pct=True).apply(df1['{variable}'.format(
            variable=group_share)].quantile)
        df2['counterfactual_total'] = df2['counterfactual_share'] * df2[
            '{total_pop}'.format(total_pop=total_population)]
        if percent:
            df1['counterfactual_total'] = df1['counterfactual_total'] / 100
            df2['counterfactual_total'] = df2['counterfactual_total'] / 100
    elif approach == 'city_composition':
        raise NotImplementedError
    elif approach == 'dual_composition':
        raise NotImplementedError
    return df1, df2
