Announcement

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

  • long database calculation

    Hello everyone,

    I have duplicated data from patients with multiple sclerosis, and I need to perform a calculation to determine a change that is sustained over time, equal to or greater than 1. If the change happens between time 1 and 2 but is not sustained between time 2 and 3, it is not suitable for my analysis.

    Thank you very much!

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float id byte time double edss_ float dif
    1  0   4    .
    2  6   5    1
    3 12 5.5   .5
    4 18 5.5    0
    5 24   6   .5
    6 30   6    0
    7 36   6    0
    1  0 6.5    .
    2  6 6.5    0
    3 12 6.5    0
    4 18   7   .5
    5 24   7    0
    6 30   .    .
    7 36   .    .
    1  0   1    .
    2  6   1    0
    3 12   1    0
    4 18   1    0
    5 24 1.5   .5
    6 30 1.5    0
    7 36 1.5    0
    1  0   5    .
    2  6   6    1
    3 12   .    .
    4 18   .    .
    5 24   .    .
    6 30   .    .
    7 36   .    .
    1  0   7    .
    2  6   7    0
    3 12 7.5   .5
    4 18 7.5    0
    5 24 7.5    0
    6 30 7.5    0
    7 36 7.5    0
    1  0   4    .
    2  6 4.5   .5
    3 12   5   .5
    4 18   5    0
    5 24   5    0
    6 30   5    0
    7 36   5    0
    1  0 6.5    .
    2  6 6.5    0
    3 12 6.5    0
    4 18 6.5    0
    5 24 6.5    0
    6 30 6.5    0
    7 36   .    .
    1  0   6    .
    2  6   5   -1
    3 12   5    0
    4 18   5    0
    5 24   5    0
    6 30   5    0
    7 36   5    0
    1  0   6    .
    2  6   6    0
    3 12   6    0
    4 18   .    .
    5 24   .    .
    6 30   .    .
    7 36   .    .
    1  0   6    .
    2  6   5   -1
    3 12   5    0
    4 18 4.5  -.5
    5 24 4.5    0
    6 30 4.5    0
    7 36 4.5    0
    1  0   6    .
    2  6   6    0
    3 12 5.5  -.5
    4 18 5.5    0
    5 24   4 -1.5
    6 30   6    2
    7 36   6    0
    1  0   4    .
    2  6   3   -1
    3 12   4    1
    4 18   4    0
    5 24   4    0
    6 30   4    0
    7 36   6    2
    1  0   6    .
    2  6   6    0
    3 12 6.5   .5
    4 18 6.5    0
    5 24 6.5    0
    6 30 6.5    0
    7 36 6.5    0
    1  0   6    .
    2  6   6    0
    3 12   6    0
    4 18   6    0
    5 24   6    0
    6 30   6    0
    7 36   6    0
    1  0   7    .
    2  6   7    0
    end

  • #2
    Hello Augusto,

    Your id variable does not identify your patients. Here's a way to correct it, assuming that the values and occurences of your time variable remain consistent for each patient:

    Code:
    gen order = _n
    by time (order), sort: gen id_v2 = _n
    sort order
    drop order
    As for your query, if I've understood correctly, the following code generates a binary variable equal to 1 if, at least once during the patient follow-up, the difference between edss_ at time m and edss_ at time m+6 is less than 1.

    Code:
    by id_v2, sort: egen flag = max(dif < 1)
    Let me know if this is not what you needed, because in your data example, the only time when flag is not equal to 1 is due to the fact that the data is missing.
    Last edited by Yanis Rahmouni; 18 Aug 2023, 07:46.

    Comment


    • #3
      Thank you very much Janis.

      It's not exactly what I want.

      What I need is to identify the patients that have a change of > 1 sustained point in time (2 times followed by a change of >= 1) of the variable edss_ .


      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input float id byte time double edss_
       1  0   4
       1  6   5
       1 12 5.5
       1 18 5.5
       1 24   6
       1 30   6
       1 36   6
       2  0 6.5
       2  6 6.5
       2 12 6.5
       2 18   7
       2 24   7
       2 30   .
       2 36   .
       3  0   1
       3  6   1
       3 12   1
       3 18   1
       3 24 1.5
       3 30 1.5
       3 36 1.5
       4  0   5
       4  6   6
       4 12   .
       4 18   .
       4 24   .
       4 30   .
       4 36   .
       5  0   7
       5  6   7
       5 12 7.5
       5 18 7.5
       5 24 7.5
       5 30 7.5
       5 36 7.5
       6  0   4
       6  6 4.5
       6 12   5
       6 18   5
       6 24   5
       6 30   5
       6 36   5
       7  0 6.5
       7  6 6.5
       7 12 6.5
       7 18 6.5
       7 24 6.5
       7 30 6.5
       7 36   .
       8  0   6
       8  6   5
       8 12   5
       8 18   5
       8 24   5
       8 30   5
       8 36   5
       9  0   6
       9  6   6
       9 12   6
       9 18   .
       9 24   .
       9 30   .
       9 36   .
      10  0   6
      10  6   5
      10 12   5
      10 18 4.5
      10 24 4.5
      10 30 4.5
      10 36 4.5
      11  0   6
      11  6   6
      11 12 5.5
      11 18 5.5
      11 24   4
      11 30   6
      11 36   6
      12  0   4
      12  6   3
      12 12   4
      12 18   4
      12 24   4
      12 30   4
      12 36   6
      13  0   6
      13  6   6
      13 12 6.5
      13 18 6.5
      13 24 6.5
      13 30 6.5
      13 36 6.5
      14  0   6
      14  6   6
      14 12   6
      14 18   6
      14 24   6
      14 30   6
      14 36   6
      15  0   7
      15  6   7
      end

      Comment


      • #4
        The syntax you previously shared works, but we need to add the following condition: a minimum of two changes equal to or greater than one continuously in time.

        Comment


        • #5
          Does this case ever happen in your data example? Based on my understanding of your request, it doesn't. Try:

          Code:
          by id (time), sort: gen dif = edss_[_n] - edss_[_n-1]
          by id (time), sort: egen flag = max(cond(missing(dif), 0, dif) >= 1 & cond(missing(dif[_n+1]), 0, dif[_n+1]) >= 1)
          and let me know if it helps. I changed your data to better represent your issue and this is what I get (changes in red):

          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input float id byte time double edss_ float(dif flag)
           1  0   4    . 1
           1  6   5    1 1
           1 12   6    1 1
           1 18   7    1 1
           1 24   6   -1 1
           1 30   6    0 1
           1 36   6    0 1
           2  0 6.5    . 0
           2  6 6.5    0 0
           2 12 6.5    0 0
           2 18   7   .5 0
           2 24   7    0 0
           2 30   .    . 0
           2 36   .    . 0
           3  0   1    . 0
           3  6   1    0 0
           3 12   1    0 0
           3 18   1    0 0
           3 24 1.5   .5 0
           3 30 1.5    0 0
           3 36 1.5    0 0
           4  0   5    . 0
           4  6   6    1 0
           4 12   .    . 0
           4 18   .    . 0
           4 24   .    . 0
           4 30   .    . 0
           4 36   .    . 0
           5  0   7    . 0
           5  6   7    0 0
           5 12 7.5   .5 0
           5 18 7.5    0 0
           5 24 7.5    0 0
           5 30 7.5    0 0
           5 36 7.5    0 0
           6  0   4    . 0
           6  6 4.5   .5 0
           6 12   5   .5 0
           6 18   5    0 0
           6 24   5    0 0
           6 30   5    0 0
           6 36   5    0 0
           7  0 6.5    . 0
           7  6 6.5    0 0
           7 12 6.5    0 0
           7 18 6.5    0 0
           7 24 6.5    0 0
           7 30 6.5    0 0
           7 36   .    . 0
           8  0   6    . 0
           8  6   5   -1 0
           8 12   5    0 0
           8 18   5    0 0
           8 24   5    0 0
           8 30   5    0 0
           8 36   5    0 0
           9  0   6    . 0
           9  6   6    0 0
           9 12   6    0 0
           9 18   .    . 0
           9 24   .    . 0
           9 30   .    . 0
           9 36   .    . 0
          10  0   6    . 0
          10  6   5   -1 0
          10 12   5    0 0
          10 18 4.5  -.5 0
          10 24 4.5    0 0
          10 30 4.5    0 0
          10 36 4.5    0 0
          11  0   6    . 0
          11  6   6    0 0
          11 12 5.5  -.5 0
          11 18 5.5    0 0
          11 24   4 -1.5 0
          11 30   6    2 0
          11 36   6    0 0
          12  0   4    . 0
          12  6   3   -1 0
          12 12   4    1 0
          12 18   4    0 0
          12 24   4    0 0
          12 30   4    0 0
          12 36   6    2 0
          13  0   6    . 0
          13  6   6    0 0
          13 12 6.5   .5 0
          13 18 6.5    0 0
          13 24 6.5    0 0
          13 30 6.5    0 0
          13 36 6.5    0 0
          14  0   6    . 0
          14  6   6    0 0
          14 12   6    0 0
          14 18   6    0 0
          14 24   6    0 0
          14 30   6    0 0
          14 36   6    0 0
          15  0   7    . 0
          15  6   7    0 0
          end
          Last edited by Yanis Rahmouni; 18 Aug 2023, 12:58.

          Comment


          • #6
            Thank you so much i really appreciate it

            Comment

            Working...
            X