Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Thank you very much Dr.Schechter ! This was extremely helpful; I'll modify the code to account for the details you mentioned!

    Comment


    • #17
      Hello! I additionally need some help. I've used the egen and group function to create a race_ethnicity variable from individual race variable responses. My code is:

      egen race_ethnicity = group(nhwhite nhblack nhasian nhna nhnh nhuk multirace pr_hsp) if(nhwhite==1 | nhblack==1 | nhasian==1 | nhna==1 | nhnh==1 | nhuk==1 | multirace==1 | pr_hsp==1)
      label define race_ethnicitylabel_2 1 "Hispanic" 2 "NH Mixed Race" 3 "NH Unknown" 4 "NH Native Hawaiian/Pacific" 5 "NH American Indian/Alaska Native" 6 "NH Asian" 7 "NH Black" 8 "NH White"

      label values race_ethnicity race_ethnicitylabel_2
      label variable race_ethnicity "Race & Ethnicity"
      tab race_ethnicity

      and it returns what is in the attached screenshot. The frequencies from NH White through NH American Indian/Alaska Native are correct. On the next line for NH Native Hawaiian it says the frequency is 11, but that is actually the frequency for the above race response (NH Unknown) and the frequency for NH Native Hawaiian is actually 0. So essentially it is shifting all the numbers down. Is there a way I can adjust my code (or create a completely new code) so that NH Native Hawaiian (or any other race for that matter) doesn't show up if the frequency is 0?

      Thank you!!
      Attached Files

      Comment


      • #18
        The problem arises because -egen, group()- cannot anticipate how you will define your label. Finding no observations where nhnh = 1, it does not reserve any numerical value for this unattested category of NH Native Hawaiian. Instead, it continues assigning consecutive numerical values to the combinations it encounters. Consequently, the label you define is out of sync with what -egen- did. So, remove NH Native Hawaiian from your label definition, and then renumber the subsequent categories to start from 4 instead of 5, and you should be OK.

        Comment

        Working...
        X