I want to calculate the median age of a population. Consider the following example data (downloaded from Statistics Canada's CANSIM database, Table 051-0001):
Table 051-0001 Estimates of population, by age group and sex for July 1, Canada, provinces and territories, annual (persons unless otherwise noted)
Survey or program details:
Estimates of Population by Age and Sex for Canada, Provinces and Territories - 3604
Geography Age 2010 2011 2012 2013 2014
Canada 0 377861 376321 376593 381689 384566
Canada 1 380538 379990 379191 379400 384085
Canada 2 380634 383179 383355 382164 382320
Canada 3 371478 383741 386305 386406 384721
Canada 4 362882 375833 387091 389512 389258
Canada 5 356590 366757 379364 390614 392709
Canada 6 360976 361038 370316 382704 393919
Canada 7 355169 363440 364337 373378 385791
Canada 8 357366 358621 366509 367203 375972
Canada 9 361252 360577 361705 369300 369853
Canada 10 374141 365198 363513 364429 371892
Canada 11 376153 376458 368165 366089 366754
Canada 12 386812 379838 379378 370725 368303
Canada 13 400765 391245 382591 381913 373366
Canada 14 421855 405425 394646 385845 385158
Canada 15 434175 426802 409598 398813 390141
Canada 16 438635 440145 432615 415325 404911
Canada 17 446950 446524 446819 438832 422155
Canada 18 457629 455872 456107 456347 449780
Canada 19 472134 469609 469648 469727 471713
Canada 20 479938 479650 480075 478935 479825
Canada 21 465581 484077 487441 487222 487303
Canada 22 451825 470052 492089 494807 494773
Canada 23 457019 458775 478405 500371 502743
Canada 24 468109 461800 466140 485206 507465
Canada 25 472877 471522 468571 472175 491796
Canada 26 471323 475052 478176 474765 478485
Canada 27 470566 474287 481927 484782 481007
Canada 28 468454 475287 481774 488559 491073
Canada 29 474732 473693 482673 488843 495415
Canada 30 468396 479377 481415 489943 495625
Canada 31 457343 472955 486914 488681 496949
Canada 32 450990 462922 480345 493717 495002
Canada 33 452786 455951 469502 486633 499657
Canada 34 454337 456750 462188 475678 492631
Canada 35 456131 457914 462422 467980 481122
Canada 36 444761 458413 463276 467283 472694
Canada 37 447653 448563 463120 467676 471389
Canada 38 454974 450150 452853 467353 471303
Canada 39 479412 458047 454151 456406 470625
Canada 40 476941 480129 461608 457435 459218
Canada 41 473754 478010 483497 464567 459997
Canada 42 470960 475541 480964 486012 466836
Canada 43 476994 473014 478112 483096 487941
Canada 44 505091 479224 475161 480000 484701
Canada 45 543975 506180 480754 476662 481251
Canada 46 560528 541424 507546 481692 477527
Canada 47 565680 557834 542469 508247 482163
Canada 48 550871 562501 558604 542971 508357
Canada 49 559845 551970 563107 558829 542849
Canada 50 549137 558958 551916 563085 558602
Canada 51 535778 548847 558693 551419 562609
Canada 52 530407 536639 548423 557898 550499
Canada 53 518528 529913 535794 547485 556782
Canada 54 501147 516903 528855 534558 546135
Canada 55 496890 501158 515688 527602 532979
Canada 56 476058 493948 499663 514369 525968
Canada 57 452959 473623 492514 498260 512603
Canada 58 434140 451080 471946 491181 496564
Canada 59 426554 433281 449217 470450 489202
Canada 60 416427 424456 431432 447732 468404
Canada 61 406686 414501 422373 429874 445569
Canada 62 406030 405624 412256 420656 427664
Canada 63 409513 404282 403263 410629 418399
Canada 64 343036 401580 401573 401279 408094
Canada 65 319975 344130 398603 399294 398380
Canada 66 310757 317981 341249 395875 396003
Canada 67 297341 306903 314982 338733 392348
Canada 68 274022 292908 303625 312358 335276
Canada 69 262547 271018 289468 300739 308870
Canada 70 243273 257990 267625 286330 297083
Canada 71 233870 240638 254195 264252 282308
Canada 72 222439 230156 236842 250713 260198
Canada 73 209795 218638 226001 233119 246393
Canada 74 205522 206400 214332 222005 228699
Canada 75 196095 200626 201812 209949 217227
Canada 76 185698 190737 195686 197222 204987
Canada 77 183420 180672 185358 190437 191834
Canada 78 177259 176879 174946 179710 184600
Canada 79 170901 170424 170616 168901 173534
Canada 80 159809 163436 163608 163924 162272
Canada 81 146075 152274 156213 156439 156796
Canada 82 137515 138753 144686 148468 148791
Canada 83 125378 129386 131081 136719 140405
Canada 84 116263 117291 121359 122961 128353
Canada 85 105468 107226 109197 112966 114566
Canada 86 94205 96193 99099 100911 104508
Canada 87 82396 85051 88042 90690 92440
Canada 88 73145 73870 77032 79728 82232
Canada 89 62417 64399 66201 69033 71573
Canada 90+ 200558 216331 233539 249385 265581
Canada MedianAge 39.8 40 40.1 40.2 40.4
Source:
Statistics Canada. Table 051-0001 - Estimates of population, by age group and sex for July 1, Canada, provinces and territories, annual (persons unless otherwise noted)
(accessed: February 24, 2015)
In order to establish the median for (say) 2010, we calculate the cumulative totals:
Geography Age 2010 Cumulative
Canada 0 377861 377861
Canada 1 380538 758399
Canada 2 380634 1139033
Canada 3 371478 1510511
Canada 4 362882 1873393
Canada 5 356590 2229983
Canada 6 360976 2590959
Canada 7 355169 2946128
Canada 8 357366 3303494
Canada 9 361252 3664746
Canada 10 374141 4038887
Canada 11 376153 4415040
Canada 12 386812 4801852
Canada 13 400765 5202617
Canada 14 421855 5624472
Canada 15 434175 6058647
Canada 16 438635 6497282
Canada 17 446950 6944232
Canada 18 457629 7401861
Canada 19 472134 7873995
Canada 20 479938 8353933
Canada 21 465581 8819514
Canada 22 451825 9271339
Canada 23 457019 9728358
Canada 24 468109 10196467
Canada 25 472877 10669344
Canada 26 471323 11140667
Canada 27 470566 11611233
Canada 28 468454 12079687
Canada 29 474732 12554419
Canada 30 468396 13022815
Canada 31 457343 13480158
Canada 32 450990 13931148
Canada 33 452786 14383934
Canada 34 454337 14838271
Canada 35 456131 15294402
Canada 36 444761 15739163
Canada 37 447653 16186816
Canada 38 454974 16641790
Canada 39 479412 17121202
Canada 40 476941 17598143
Canada 41 473754 18071897
Canada 42 470960 18542857
Canada 43 476994 19019851
Canada 44 505091 19524942
Canada 45 543975 20068917
Canada 46 560528 20629445
Canada 47 565680 21195125
Canada 48 550871 21745996
Canada 49 559845 22305841
Canada 50 549137 22854978
Canada 51 535778 23390756
Canada 52 530407 23921163
Canada 53 518528 24439691
Canada 54 501147 24940838
Canada 55 496890 25437728
Canada 56 476058 25913786
Canada 57 452959 26366745
Canada 58 434140 26800885
Canada 59 426554 27227439
Canada 60 416427 27643866
Canada 61 406686 28050552
Canada 62 406030 28456582
Canada 63 409513 28866095
Canada 64 343036 29209131
Canada 65 319975 29529106
Canada 66 310757 29839863
Canada 67 297341 30137204
Canada 68 274022 30411226
Canada 69 262547 30673773
Canada 70 243273 30917046
Canada 71 233870 31150916
Canada 72 222439 31373355
Canada 73 209795 31583150
Canada 74 205522 31788672
Canada 75 196095 31984767
Canada 76 185698 32170465
Canada 77 183420 32353885
Canada 78 177259 32531144
Canada 79 170901 32702045
Canada 80 159809 32861854
Canada 81 146075 33007929
Canada 82 137515 33145444
Canada 83 125378 33270822
Canada 84 116263 33387085
Canada 85 105468 33492553
Canada 86 94205 33586758
Canada 87 82396 33669154
Canada 88 73145 33742299
Canada 89 62417 33804716
Canada 90+ 200558 34005274 <--- Total population
The total population contains $34\,005\,274$ individuals, with the "middle (or median) person" being person number $34\,005\,274 \div 2 = 17\,002\,637 = M$. A lookup shows that this person is said to be between 38 and 39 years old since
$$
\text{Cumulative}(38) = \overbrace{16\,641\,790}^{C(38)}
< \overbrace{17\,002\,637}^{M}
< \overbrace{17\,121\,202}^{C(39)}
= \text{Cumulative}(39).
$$
To estimate the proportion between 38 and 39, we assume that the population is evenly distributed between the age cohorts based on the cohort size. As such, this "median person" has age
$$
38 +
\frac{\overbrace{17\,002\,637}^M – \overbrace{16\,641\,790}^{C(38)}}
{\underbrace{17\,121\,202}_{C(39)} – \underbrace{16\,641\,790}_{C(38)}}
= 38 + \frac{360\,847}{479\,412}
\approx 38.8
= \bar{M}.
$$
In the above calculation, the "median cohort portion" is calculated to estimate the age above the cohort division.
To me this approach seems intuitive and sound. However, Statistics Canada reports the median age as
$$
39.8 = \bar{M} + 1.
$$
Why is that?
I assume this has to do with the fact that the population cohort aged 20 (say) is in their 21st year of life? Even if this is the case, a median age of 39.8 points to someone that is older than 39*, yet the "median person" is somewhere between 38 and 39 years old; i.e., younger than 39. Unless, of course, that proposition is incorrect.
Best Answer
The trick here is understanding the grouping categories of age here. The age group "39" is people aged 39 to less than 40 (i.e. 39 - 39.99999999). So if you look at the cumulative total for the 38 year old group, you will see the value is 16,641,790 as you've correctly noted. The cumulative total for the 39 year old group, which is really the "39 to < 40 year old group) is 17,121,202. There are a total of 479,412 individuals who are older than 39 and less than 40. We know from your table that there are 16,641,790 individuals who are less than 39 years old. So starting at person 16,641,791 and going through person 17,121,202 we find our 39 to less than 40 year olds. There are 479,412 people in this group. By your faulty assumption of equal distribution of ages, if we take $479,412\over10$, we can construct the following table, roughly, by adding this amount to the end of the cumulative figure of the 38th age group in an iterative fashion:
According to these calculations, the median would fall somewhere around 39.7. Of course, birthday months and ages are not uniformly distributed, so this accounts for the 0.2 discrepancy we see between this "on the back of a napkin" calculation and the official statistic.
I hope this helps.