computing the average of variables with missing values in Stata -
i know how calculate avarage of variables without missing value, not sure calculating missing values. example have 6 area halls follows:
area_hall_1 area_hall_2 area_hall_3 area_hall_4 area_hall_5 area_hall_6 580 580 650 . . . 1000 1000 . . . 825 825 . . . . 912 912 . . . . 670 . . . . . 790 . . . . . 750 900 1000 1000 900 750
the reported (or rather implied) problem makes no sense whatsoever. consider data posted (an missing value needed in second observation).
. clear . input area_hall_1 area_hall_2 area_hall_3 area_hall_4 area_hall_5 area_hall_6 area_ha~1 area_ha~2 area_ha~3 area_ha~4 area_ha~5 area_ha~6 1. 580 580 650 . . . 2. 1000 1000 . . . . 3. 825 825 . . . . 4. 912 912 . . . . 5. 670 . . . . . 6. 790 . . . . . 7. 750 900 1000 1000 900 750 8. end . egen area_hall_mean = rowmean(area_hall_?) . egen area_hall_count = rownonmiss(area_hall_?) . l *_mean *_count , sep(0) +---------------------+ | area_h~n area_h~t | |---------------------| 1. | 603.3333 3 | 2. | 1000 2 | 3. | 825 2 | 4. | 912 2 | 5. | 670 1 | 6. | 790 1 | 7. | 883.3333 6 | +---------------------+ . di (580+580+650)/3 603.33333
the egen
function rowmean()
ignores missing values. how otherwise? other possibility report mean cannot calculated because there missing values. defensible, not @ typical stata style. means reported op wants. independent calculation display
shows means reported desired. (a profound sceptic @ liberty inspect code viewsource _growmean.ado
.)
Comments
Post a Comment