I am trying to count the number of clinics, and compare the average proportion of patients taking Metformin, where: (1) both male and female categories have sufficient denominators to be included in the sample, (2) either male or female categories have sufficient denominators to be included in the sample, and (3) neither male nor female categories have a sufficient denominator to be included in the sample (this third category would simply be a count, since the data is missing and a proportion cannot be calculated).
I have counted the number of clinics and calculated the average proportion when a clinic has data for both men and women using this code:
bysort practice_site_id(disparities_strata) : gen paired_male = a_male_proportion if (a_female_proportion[_n-1]!=.)
As well as the proportion when there is data for only men or women:
bysort practice_site_id(disparities_strata) : gen only_male = a_male_proportion if (a_female_proportion[_n-1]==.)
I’m stuck trying to simply count the number of clinics that are missing data for both males and females. I tried to create an indicator variable for clinics missing data on males and females using this code:
bysort practice_site_id disparities_strata: gen male_female_neither=1 if (a_male_proportion==. & a_female_proportion[_n-1]==.)
But this results in a variable with an indicator “1” for every line, and shows missing when both male and female data are present, when I want to know when neither category is present.
I am using Stata 15.1 on Windows 10.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte clinic_id int(met_numerator met_denominator) str37 description double(met_proportion a_male_proportion a_female_proportion paired_male paired_female only_male only_female) byte male_female_neither 1 146 196 "1 Gender: Female" .7448979616165161 . .7448979616165161 . .7448979616165161 . . 1 1 147 192 "2 Gender: Male" .765625 .765625 . .765625 . . . . 1 162 203 "3 Race: White" .7980295419692993 . . . . . . 1 1 97 137 "4 Race: Black" .7080292105674744 . . . . . . 1 1 11 15 "5 Ethnicity: Hispanic or Latino" .7333333492279053 . . . . . . 1 1 280 369 "6 Ethnicity: Not Hispanic/Not Latino" .7588075995445251 . . . . . . 1 2 6 27 "2 Gender: Male" .2222222238779068 .2222222238779068 . . . .2222222238779068 . 1 2 4 15 "3 Race: White" .2666666805744171 . . . . . . 1 2 4 25 "4 Race: Black" .1599999964237213 . . . . . . 1 2 9 43 "6 Ethnicity: Not Hispanic/Not Latino" .20930232107639313 . . . . . . 1 3 0 126 "3 Race: White" 0 . . . . . . 1 3 0 127 "6 Ethnicity: Not Hispanic/Not Latino" 0 . . . . . . 1 4 20 88 "1 Gender: Female" .22727273404598236 . .22727273404598236 . . . .22727273404598236 1 4 47 173 "3 Race: White" .27167630195617676 . . . . . . 1 4 20 65 "4 Race: Black" .3076923191547394 . . . . . . 1 4 66 237 "11 Ethnicity: Not Hispanic/Not Latino" .27848100662231445 . . . . . . 1 end
0 Response to generating a count using stratified data
Post a Comment