I am trying to create a bar graph of calculated means of variable from the NSFG. I learned that I should not drop cases or use if-statements to subset the data when using survey weights, so I created a variable 'samp40' that includes only women ages 40 and older, my population of interest. I use the followinng code to calculate the percentage women who would like to have another child by race/ethnic group:
svy, subpop(samp40): mean wantsanother, over(race_eth)
I would now like to create a bar graph of this information (Percentage of women over 40 who want another child, by race), but I cannot figure out how to create a single variable with these values. Normally, I would create it usign the following:
egen mnwantsanother_race=wtmean(wantsanother) if samp40, by(race_eth) weight(weightvar)
However, this does not give me the correct mean values because I used the if-statement to subset the data. I also cannot use the svy prefix with the egen command.
I appreciate any help you can provide!
(I am using Stata 16 on Windows 11)
svy, subpop(samp40): mean wantsanother, over(race_eth)
I would now like to create a bar graph of this information (Percentage of women over 40 who want another child, by race), but I cannot figure out how to create a single variable with these values. Normally, I would create it usign the following:
egen mnwantsanother_race=wtmean(wantsanother) if samp40, by(race_eth) weight(weightvar)
However, this does not give me the correct mean values because I used the if-statement to subset the data. I also cannot use the svy prefix with the egen command.
I appreciate any help you can provide!
(I am using Stata 16 on Windows 11)
Comment