Announcement

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

  • Analyzing two time points

    I am analyzing data with the mental health component score (measured 0-100) for 4500 individuals. This score was measured at baseline and then 30 days following an intervention. Is there any way to identify the number of individuals whose score decreased, increased, or had no change?

  • #2
    I assumed your data were in a "long format"

    Code:
    *** I created some toy data
    dataex id time score // To install: ssc install dataex
    clear
    input byte(id time score)
    1 1 21
    1 2 95
    2 1 38
    2 2  4
    3 1 98
    3 2 98
    4 1 50
    4 2 12
    5 1 33
    5 2 91
    6 1 21
    6 2 52
    end
    
    bysort id (time): gen wanted = "Increased" if score[2] > score[1] & score[2]!=.
    bysort id (time): replace wanted = "No change" if score[2] == score[1] & score[2]!=.
    bysort id (time): replace wanted = "Decreased" if score[2] < score[1] & score[2]!=.
    gen d_increased = (wanted=="Increased")  // 1 if wanted=="Increased", 0 otherwise
    
    . list, sepby(id) abbrev(12) noobs
    
      +---------------------------------------------+
      | id   time   score      wanted   d_increased |
      |---------------------------------------------|
      |  1      1      21   Increased             1 |
      |  1      2      95   Increased             1 |
      |---------------------------------------------|
      |  2      1      38   Decreased             0 |
      |  2      2       4   Decreased             0 |
      |---------------------------------------------|
      |  3      1      98   No change             0 |
      |  3      2      98   No change             0 |
      |---------------------------------------------|
      |  4      1      50   Decreased             0 |
      |  4      2      12   Decreased             0 |
      |---------------------------------------------|
      |  5      1      33   Increased             1 |
      |  5      2      91   Increased             1 |
      |---------------------------------------------|
      |  6      1      21   Increased             1 |
      |  6      2      52   Increased             1 |
      +---------------------------------------------+
    
    // NOTE: The above puts "Increased", "Decreased", etc in both observations.  If you only want one obs per person marked
    bysort id (time): replace wanted = "" if _n==1
    bysort id (time): replace d_increased  = . if _n==1
    
    . list, sepby(id) abbrev(12) noobs
    
      +---------------------------------------------+
      | id   time   score      wanted   d_increased |
      |---------------------------------------------|
      |  1      1      21                         . |
      |  1      2      95   Increased             1 |
      |---------------------------------------------|
      |  2      1      38                         . |
      |  2      2       4   Decreased             0 |
      |---------------------------------------------|
      |  3      1      98                         . |
      |  3      2      98   No change             0 |
      |---------------------------------------------|
      |  4      1      50                         . |
      |  4      2      12   Decreased             0 |
      |---------------------------------------------|
      |  5      1      33                         . |
      |  5      2      91   Increased             1 |
      |---------------------------------------------|
      |  6      1      21                         . |
      |  6      2      52   Increased             1 |
      +---------------------------------------------+
    
    
    . tabulate wanted
    
         wanted |      Freq.     Percent        Cum.
    ------------+-----------------------------------
      Decreased |          2       33.33       33.33
      Increased |          3       50.00       83.33
      No change |          1       16.67      100.00
    ------------+-----------------------------------
          Total |          6      100.00

    Comment


    • #3
      Thank you for answering my question!

      Comment


      • #4
        Here is some more technique. I stole david Benson's data example and some of his ideas from his helpful post.

        Code:
        nput byte(id time score)
        1 1 21
        1 2 95
        2 1 38
        2 2  4
        3 1 98
        3 2 98
        4 1 50
        4 2 12
        5 1 33
        5 2 91
        6 1 21
        6 2 52
        end
        
        bysort id (time) : gen previous = score[1] if _n == 2 
        
        scatter score previous 
        
        gen change = score - previous 
        gen sign = sign(change)
        
        label def sign -1 "Down" 0 "Same" 1 "Up"
        label val sign sign 
        
        tab sign 
        
             sign |      Freq.     Percent        Cum.
        ------------+-----------------------------------
               Down |          2       33.33       33.33
               Same |          1       16.67       50.00
                 Up |          3       50.00      100.00
        ------------+-----------------------------------
              Total |          6      100.00


        The same information: but the values -1 0 1 ensure the right order: alphabetical order doesn't do quite the right thing in David's table.

        Comment


        • #5
          This is helpful, thank you.

          Comment

          Working...
          X