Skip to content

preprocess_simulated_variables

preprocess_simulated_variables(data: DataFrame) -> DataFrame

Post-processes the simulated variables.

Calculates the total exemptions, total reductions, and total exemptions and reductions. Corrects the unemployment benefits and calculates the gross salary.

Parameters:

Name Type Description Default
data DataFrame

The input data with simulated variables.

required

Returns:

Type Description
DataFrame

The post-processed data.

Source code in bozio_wasmer_simulations/simulation/empirical/preprocessing.py
def preprocess_simulated_variables(data: pd.DataFrame) -> pd.DataFrame:
    """
    Post-processes the simulated variables.

    Calculates the total exemptions, total reductions, and total exemptions and reductions.
    Corrects the unemployment benefits and calculates the gross salary.

    Args:
        data (pd.DataFrame):
            The input data with simulated variables.

    Returns:
        (pd.DataFrame): The post-processed data.
    """
    # Somme des exonérations
    data["exonerations"] = (
        data[
            [
                "exoneration_cotisations_employeur_apprenti",
                "exoneration_cotisations_employeur_jei",
                "exoneration_cotisations_employeur_zrd",
                "exoneration_cotisations_employeur_zrr",
                "exoneration_cotisations_employeur_stagiaire",
            ]
        ].sum(axis=1)
        - data["exoneration_cotisations_employeur_tode"]
    )
    # Somme des allègements
    data["allegements"] = data[
        [
            "allegement_general",
            "allegement_cotisation_maladie",
            "allegement_cotisation_allocations_familiales",
        ]
    ].sum(axis=1)
    # Somme des exonérations et allègements
    data["exonerations_et_allegements"] = data[["exonerations", "allegements"]].sum(
        axis=1
    )
    # Correction des allocations chomages
    data["cotisations_employeur"] = (
        data["cotisations_employeur"]
        - data["chomage_employeur"]
        - data["assiette_cotisations_sociales"] * 0.0405
        - data[
            [
                "allegement_cotisation_maladie",
                "allegement_cotisation_allocations_familiales",
            ]
        ].sum(axis=1)
    )
    # Extraction des bandeaux de la variable hors allegements
    data["salaire_super_brut_hors_allegements"] = (
        data["salaire_super_brut_hors_allegements"]
        - data["chomage_employeur"]
        - data["assiette_cotisations_sociales"] * 0.0405
        + data[
            [
                "allegement_cotisation_maladie",
                "allegement_cotisation_allocations_familiales",
            ]
        ].sum(axis=1)
    )
    # Suppression de la colonne "chomage_employeur"
    # data.drop('chomage_employeur', axis=1, inplace=True)
    # Calcul du salaire super brut
    data["salaire_super_brut"] = (
        data["salaire_super_brut_hors_allegements"]
        - data["exonerations_et_allegements"]
        + data["prime_partage_valeur_exoneree"]
    )

    return data