Announcement

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

  • Complicated coding - female/male friends - same sex or mixed-sex

    Dear members,
    I am struggling with a complicated coding.

    I have female_friends and male_friends. Each of the variable has 0 friends (0), 1-2 friends (1) 3-4 or more (2)- 3 categories. Then I have a variable "gender" (males = 0, females=1)

    For a new variable, I would like to create 1= no friends or same-sex friends and 2= mixed sex friends (a female having both female and male friends, a male having both male and female friends).

    The new variable can be called "peers_sex_composition"

    If a female (or male) does not have any friends (female_friends = 0 & male_friends = 0) then the new variable should be coded as 1.
    If a female has only female_friends = 1/2 BUT male_friends =0, then this also should be coded as 1.
    If a female has mixed sex friends (both female and male friends) in other words, female_friends= 1/2 & male_friends =1/2 then new variable will be 2.

    For the male, it would be the same (3 options) but both female and male should be combined into one single new variable "peers_sex_composition."

    Please, could you help me with syntax?

    Thanks
    best, Rinko

  • #2
    I would advise against coding this new variable 1/2 as it is binary. It would appear that the gender variable is irrelevant here as your requirement is an individual (whether male or female) having friends of both sexes.

    Code:
    bysort pid: gen wanted= inlist(male_friends, 1, 2) & inlist(female_friends, 1, 2)

    where pid is the individual identifier. This variable is coded 1 if an individual has friends of both sexes and zero otherwise. If this does not solve your problem, provide a data example using the dataex command (refer to FAQ Advice #12 for details).

    Comment


    • #3
      Andrew Musau Thanks for your help. I tried, it works but after this syntax, I don't know what to do in order to use this variable in multiple regression models. this is what I did and I didn't get error message, meaning it worked.
      Thanks Rinko

      bysort surid: gen wanted= inlist(male_friends, 1, 2) & inlist(female_friends, 1, 2)

      Comment


      • #4
        Andrew Musau Now I understood. the new variable "wanted" was created. thanks so much

        . tab wanted

        wanted Freq. Percent Cum.

        0 197 34.62 34.62
        1 372 65.38 100.00

        Total 569 100.00


        | IA2. Are you a ….?
        wanted | Boy Girl | Total
        -----------+----------------------+----------
        0 | 67 130 | 197
        | 28.88 38.58 | 34.62
        -----------+----------------------+----------
        1 | 165 207 | 372
        | 71.12 61.42 | 65.38
        -----------+----------------------+----------
        Total | 232 337 | 569
        | 100.00 100.00 | 100.00

        Comment


        • #5
          Probably best to name it "both_friends" or something more informative.

          Comment


          • #6
            Genius! thanks so much.

            Comment

            Working...
            X