Announcement

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

  • Creating a new variable based on multiple existing variables

    Hi!
    I have a dataset with loads of variables. I am looking into factors associated with childhood development. For a child to be developmentally on track, they need to check at least x/20 variables depending on age. I want to make a new variable that for each child tells me if they´re developmentally on track (checks at least 15/20 variables for the age category I´m interested in). I have named the 20 variables I´m interested in "var1, var2, var3.." etc. How do I make a new variable for each child that tells me if they´re on track yes/no?

    Thanks!

  • #2
    In detail, the answer depends on how you are coding yes and no. If yes is 1 and no is 0 you can go

    Code:
    egen wanted = rowtotal(var1-var20)
    If you're using some other numbers, some egen function like anycount() should help. help egen for more

    If you are using strings, here is some token technique:

    Code:
    gen wanted = 0 
    
    forval j = 1/20 { 
          replace wanted = wanted + (var`j' == "yes")  
    }
    If that's not enough to answer your question please visit https://www.statalist.org/forums/help#stata and give us more by way of detail.

    Comment


    • #3
      Thank you!

      Comment

      Working...
      X