Field note · October 28, 2023

salary_max_usd by country: a 379% spread

Real group means for one column across 7 segments, and what the pooled average conceals.

1 min read ·Analytics practice ·statistics practice

Breaking salary_max_usd down by country on data-job-postings, because the headline average is 138,807 and no segment is actually there.

  • US — mean 160,050, median 158,500 (1,579 rows)
  • GB — mean 85,831, median 92,000 (436 rows)
  • NL — mean 83,441, median 92,500 (245 rows)
  • CA — mean 78,931, median 89,500 (247 rows)
  • DE — mean 78,458, median 87,000 (333 rows)
  • BR — mean 40,846, median 45,000 (243 rows)

Top to bottom that is 160,050 against 33,385, a spread of 379.4%. The pooled average is 138,807.

sql
select country,
  count(*)                                                    as rows,
  round(avg(salary_max_usd)::numeric, 2)                      as mean,
  percentile_cont(0.5) within group (order by salary_max_usd) as median
from data_job_postings
group by 1
order by mean desc;

A spread that wide means the pooled number is not a summary, it is an artefact of the mix. Change the proportion of US rows and the overall average moves without any individual group changing at all — which is how a metric goes up while every segment goes down.

Notice the mean and median columns disagree only slightly here. Always compute both in the group-by. The comparison between them per segment is free and tells you whether you are looking at a level difference or a tail difference.

This is the setup for Simpson's paradox — the case where every segment moves one way and the total moves the other.