Calculate achievement gap between two subgroups
Source:R/percentile_rank.R
calculate_subgroup_gap.RdCalculates the difference in a metric between two subgroups within each entity (district/school) and year. The gap is calculated as subgroup_a - subgroup_b, so positive values mean subgroup_a outperforms.
Usage
calculate_subgroup_gap(
df,
metric_col,
subgroup_a,
subgroup_b,
year_col = "end_year",
entity_cols = "district_id"
)Arguments
- df
Dataframe with a 'subgroup' column and the metric of interest
- metric_col
Character. The column containing the metric to compare.
- subgroup_a
Character. The reference subgroup (typically majority/advantaged).
- subgroup_b
Character. The comparison subgroup (typically minority/disadvantaged).
- year_col
Character. Year column name. Default "end_year".
- entity_cols
Character vector. Columns identifying the entity (e.g., c("district_id") or c("county_id", "district_id", "school_id")).