Announcement

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

  • Creating a variable to show response patterns

    Dear all

    I have 3 variables in long format.
    1. pid
    2. qnum - question number (1-16)
    3. asthq - binary response to qunum

    I would like to create a new variable to indicate a particular response pattern within id over the variable asthq (e.g., 0=all zeroes, and so forth).

    I would be grateful for any advice on how to do this.

    Code:
         +--------------------+
         | pid   qnum   asthq |
         |--------------------|
      1. |   1      1     Yes |
      2. |   1      2     Yes |
      3. |   1      3      No |
      4. |   1      4      No |
      5. |   1      5      No |
         |--------------------|
      6. |   1      6      No |
      7. |   1      7      No |
      8. |   1      8      No |
      9. |   1      9     Yes |
     10. |   1     10     Yes |
         |--------------------|
     11. |   1     11     Yes |
     12. |   1     12      No |
     13. |   1     13     Yes |
     14. |   1     14     Yes |
     15. |   1     15      No |
         |--------------------|
     16. |   1     16     Yes |
     17. |   2      1     Yes |
     18. |   2      2     Yes |
     19. |   2      3     Yes |
     20. |   2      4     Yes |
         |--------------------|
     21. |   2      5     Yes |
     22. |   2      6     Yes |
     23. |   2      7     Yes |
     24. |   2      8     Yes |
     25. |   2      9     Yes |
         |--------------------|
     26. |   2     10     Yes |
     27. |   2     11     Yes |
     28. |   2     12     Yes |
     29. |   2     13     Yes |
     30. |   2     14     Yes |
         +--------------------+

  • #2
    The "particular response pattern" was not fully clarified in #1.

    That said, you may wish to check - egen - command and options.
    Best regards,

    Marcos

    Comment


    • #3
      Sorry - I want to identify all different types of response patterns across 16 variables (all 0s is just one of them).

      Comment


      • #4

        You seem to have 16 observations for each identifier, not 16 variables.

        Perhaps what you want is

        Code:
        reshape wide asthq, i(pid) j(qnum) 
        
        egen pattern = concat(asthq*) 
        
        tab pattern 

        Comment


        • #5
          Thank you Nick! Now that I have my patterns, are you able to advise on how to assign a code to each pattern type which is equal to the frequency as I need to use this as a weight in my model? For example, from the patterns below, 99 individuals would have a weight of 99?
          Code:
                   pattern |      Freq.     Percent        Cum.
          -----------------+-----------------------------------
          0000000000000000 |         99       19.15       19.15
          0000000000000100 |          5        0.97       20.12
          0000000001000110 |          1        0.19       20.31
          0000000001001010 |          3        0.58       20.89
          0000000001001110 |          1        0.19       21.08
          0000000001001111 |          1        0.19       21.28
          0000000001101010 |          5        0.97       22.24
          0000000001101011 |          3        0.58       22.82
          0000000011000011 |          1        0.19       23.02
          0000000011000110 |          1        0.19       23.21
          0000000100000000 |          4        0.77       23.98
          0000000111100011 |          1        0.19       24.18
          0000001000000000 |         18        3.48       27.66
          0000001001001010 |          1        0.19       27.85
          0000001001001110 |          1        0.19       28.05
          0000001001101010 |          2        0.39       28.43
          0000001001101011 |          3        0.58       29.01
          0000001111100111 |          1        0.19       29.21
          0000100000000000 |          2        0.39       29.59
          0000100001101000 |          1        0.19       29.79
          0000100001101011 |          1        0.19       29.98
          0001000000000000 |         80       15.47       45.45
          Last edited by Sara Khan; 10 Feb 2017, 08:17.

          Comment


          • #6
            That sounds completely unnecessary: if a pattern is repeated so many times, that will be its weight in fitting a model automatically.

            Comment

            Working...
            X