Announcement

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

  • 5 categorical variables into 1

    Hi, I am new to Stata, so please appologize my basic question - any help would be highly appreciated!

    I have a dataset from a questionnaire on musculoskeletal disorders.
    The questionnaire repeat itself in case of multiple injuries- and my question is how I can sum up these scores by creating a new variable with the total sum.
    Example: q15: Was it an acute injury, or did it develop over time? 1= acute, 2= overuse injury
    question q25 is identical conserning a second injury
    question q35 is identical conserning a third injury and same with the forth and fifth injury
    q15 q25 q35 q45 q55 sum
    id1 acute overuse overuse overuse overuse 1 acute 4 overuse
    id2 overuse acute 1 acute 1 overuse
    id3 acute overuse overuse 1 acute 2 overuse
    3 acute 7 overuse
    So I want to create a varible with the total sum 3 acute and 7 overuse injuries.
    I have tried without any luck (or more precise; I manage to create the variable, but it doesn't give me the sum I am looking for):
    generate OceruseAcuteALL = q15+q25+q35+q45+q55
    egen OceruseAcuteALL= concat (q15 q25 q35 q45 q55)
    egen byte OceruseAcuteALL= anycount( q15 q25 q35 q45 q55), values (1 2)
    They all seem to sum up, mixing 1'ers and 2'ers, treating them as continous? - but I want to separate 1'ers (acute) and 2'ers (overuse)

    I have the same problem for example with the question on witch bodypart that is injured: q16+q26+q36+q46+q56 where each bodypart have the same value label for each question, i.e. low back pain have value 8. I want to find how many problems in total wiht low back pain, how many shoulder etc.

    I am superhappy if anyone can give me a hint on how to do it.
    Best regards
    Rannveig

  • #2
    Hello Rannveig Mowinckel. Take a look at anycount() function under help egen. (And see the FAQ advice on how to post usable sample data via the -dataex- command.)

    Code:
    * Read in the sample data
    clear
    input id q15 q25 q35 q45 q55
    1     1     2     2     2     2
    2     2     1   .   .   .            
    3     1     2     2     .   .
    end
    
    * Count the number of 1s
    egen acute = anycount(q15 q25 q35 q45 q55), values(1)
    * Count the number of 2s
    egen overuse = anycount(q15 q25 q35 q45 q55), values(2)
    list
    * Show the sums of the two counts
    tabstat acute overuse, statistics( sum )

    HTH.
    --
    Bruce Weaver
    Email: [email protected]
    Version: Stata/MP 19.5 (Windows)

    Comment


    • #3
      Hello @Bruce Weaver!
      THANK YOU - THANK YOU - THANK YOU!
      This works perfectly. I am over the moon!!
      Best regards Rannveig

      Comment

      Working...
      X