Announcement

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

  • Generating New Variable

    I want to generate a new dichotomous variable where 1 denotes the presence of one or more types of abuse - verbal abuse, sexual abuse, and physical abuse - and 0 denotes the absence of any abuse. Verbal abuse, sexual abuse, and physical abuse variables already exist. People could have experienced multiple forms of abuse. Would the code below work?

    gen anyabuse=1 if verbal==1 | sexual==1 | physical==1

    replace anyabuse=0 if anyabuse!=1


  • #2
    Great question, please provide us your dataset using dataex.

    Comment


    • #3
      Assuming the original values are 0, 1 or just possibly missing

      Code:
      gen anyabuse = verbal==1 | sexual==1 | physical==1
      would do what you want, as would

      Code:
      gen anyabuse = inlist(1, verbal, sexual, physical)
      as would (but this time missing values are not allowed)

      Code:
      gen anyabuse = verbal | sexual | physical
      For more background, see https://www.stata-journal.com/articl...article=dm0099 or https://www.stata-journal.com/articl...article=dm0087 or https://www.stata.com/support/faqs/d...rue-and-false/

      Comment


      • #4
        Unfortunately, I don't have access to it and am merely trying to help a colleague troubleshoot. Are you able to answer without it?

        Comment


        • #5
          I think #4 was an answer to #2.

          Comment

          Working...
          X