Announcement

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

  • comparing variables

    Hi, can someone can help me with this query ?
    I have 12 numerical variables for each subject, 6 variables are before an intervention (pre1, pre2, pre3, pre4, pre5 and pre6) and 6 are after an intervention (post1, post2, post3, post4, post5 and post6). I need to work out for each subject if any 3 of the 6 post intervention variables has decreased by 30% and in the remaining 3/6 variables, if ≤1 variables has increased by 30%.
    I have generated a new set of variables which are ± 30% of the pre-variable values to compare with corresponding post-variables. But since it is any 3 out of any 6 variables and then choosing the remaining 3 variables to compare, I am unable to write a script for this. I have tried searching for related previous posts here but couldn’t find any. I am relatively new to stata, any help is greatly appreciated.
    Thanks
    Sunil

  • #2
    There are several ways one could do this. Here's one approach I might use. I assume you have a subject id variable called id.

    Code:
    reshape long pre post, i(id) j(meas_num)
    gen rel_diff = (post-pre)/pre
    gen byte incr_30 = (rel_diff > 0.3) if !missing(rel_diff)
    gen byte decr_30 = (rel_diff < -0.3) if !missing(rel_diff)
    by id, sort: gen byte num_incr_30 = total(incr_30)
    by id: gen byte num_decr_30 = total(decr_30)
    gen byte criterion = num_decr_30 >= 3 & num_incr_30 <= 1
    
    // OPTIONALLY RESTORE WIDE FORMAT TO DATA
    reshape wide pre post incr_30 decr_30, i(id) j(meas_num)
    Caveat: not tested, but I think it's right.

    The variable criterion will indicate the observations fitting your description.

    Comment


    • #3
      Before I saw Clyde's most helpful reply, my one thought was "you need to reshape". As he has done the hard bit, I will do the easy bit and underline that the kind of comparison you want to do will be much easier with a different structure.

      What's magic about 30%?

      Comment


      • #4
        Hi Clyde and Nick
        Thank you for taking time to respond and help with this. 30 % is just one of the levels of response to a treatment in rheumatic conditions , hence I was interested .
        BW
        Sunil

        Comment

        Working...
        X