Announcement

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

  • calculus long clinical research

    Hello, good afternoon, greetings to all

    I have this repeated measures data set.
    I need to mark the patients that meet the condition that the value in both variables is 1.

    Thank you so much !


    clear
    input str9 id float(date previous_date) byte(nlest2 spinal_cord)
    "10005472" 19015 . 1 1
    "10020170" 18590 . 1 1
    "10020170" 20368 18590 1 1
    "10020777" 17855 . 1 1
    "10020777" 17981 . 1 1
    "10067748" 21962 21833 10 3
    "10087618" 14741 . 7 1
    "10087618" 16579 14741 10 1
    "10203595" 17774 . 10 3
    "10239623" 17821 17465 10 2
    "10269479" 14347 . 10 2
    "10269479" 16198 14347 10 1
    "10269479" 18002 16198 10 1
    "10269479" 19820 18002 10 1
    "10269479" 23147 20859 10 3
    "10309749" 20830 . 3 1
    "10329252" 22027 . 10 1
    "10369688" 18241 . 10 1
    "10427832" 17974 . 9 1
    "10430583" 17960 . 10 1
    "10443903" 20557 20457 2 1
    "10443903" 20557 . 2 1
    "10446691" 13724 . 10 1
    "10446691" 15585 13724 10 1
    "10446691" 17227 15585 10 1
    "10446691" 20914 20130 10 4
    "10455777" 17231 . 5 2
    "10461822" 20486 19013 1 1
    "10490935" 13986 . 10 1
    "10525421" 23056 22678 10 4
    "10541670" 17353 16381 10 2
    "10543947" 14221 . 10 1
    "10543947" 15608 14221 10 1
    "10543947" 17386 15608 10 1
    "10544296" 18172 . 1 1
    "10552683" 22132 . 10 2
    "10552683" 22316 22132 10 2
    "10552683" 22698 22316 10 3
    "10552683" 23051 22698 10 3
    "10582578" 20025 19096 10 4
    "10660897" 18110 . 6 1
    "10715060" 14663 . 7 1
    "10715060" 15016 14663 7 1
    "10715060" 16933 15016 10 1
    "10718399" 22999 22590 10 1
    "10739912" 13859 . 2 1
    "10739912" 15679 14220 2 1
    "10739912" 17513 15679 2 1
    "10833536" 21881 21546 1 1
    "10836550" 13781 . 8 2
    "10836550" 14140 13781 9 1
    "10836550" 15602 14140 10 1
    "10836550" 15602 17793 10 1
    "10836550" 17386 15602 10 1
    "10836550" 22342 21115 10 3
    "10836550" 22828 22342 10 3
    "10844214" 23095 22679 10 4
    "10863990" 18744 . 1 2
    "10863990" 19094 19110 1 1
    "10875123" 14910 . 10 1
    "10875123" 15273 14910 10 1
    "10875123" 16729 15273 10 1
    "10875123" 18588 16729 10 1
    "10909624" 20032 . 10 4
    "10913259" 21579 . 10 3
    "10939789" 18084 . 10 2
    "10939789" 18158 18074 10 1
    "10939789" 18158 . 10 1
    "10960628" 13107 . 9 1
    "10981293" 12849 . 10 1
    "10981293" 13566 12849 10 1
    "10981293" 15124 13566 10 1
    "10981293" 17345 15124 10 2
    "109834" 13048 . 1 1
    "109834" 13339 13048 1 1
    "109834" 16624 13339 1 1
    "11042733" 19850 . 1 1
    "11042733" 20123 19850 1 1
    "11081919" 22913 22745 10 1
    "11081919" 23085 22913 10 1
    "11091023" 22377 21508 10 4
    "11091023" 23126 22377 10 4
    "11097546" 19148 . 5 1
    "11140827" 18191 18093 1 2
    "11140827" 18191 . 1 2
    "11140827" 22039 21676 6 1
    "11148755" 22846 . 10 2
    "11337630" 19997 . 10 4
    "11376065" 17804 . 1 1
    "11376065" 19859 18052 1 1
    "11381717" 14216 . 1 1
    "11381717" 14606 14216 1 1
    "11381717" 16160 14606 1 1
    "11381717" 17845 16160 1 1
    "11391472" 14500 . 6 1
    "11391472" 14871 14500 7 1
    "11391472" 16365 14871 7 1
    "11391472" 18149 16365 7 1
    "11391472" 19979 18149 10 1
    "11414155" 13283 . 8 1
    end
    format %dD_m_CY date
    format %dD_m_CY previous_date
    [/CODE]

  • #2
    your question is unclear in a couple of ways

    the first is trivial: by "both variables", I assume mean nlest2 and spinal_cord, correct?

    the second, however, is not - do they each have to "1" within the same observation or can the 1's appear in different observations for the same id as they do for id "11140827" where one observation has "1 2" and another has "6 1" for the two variables?

    Comment


    • #3
      Augusto:
      If I get you right you're looking for:
      Code:
      bysort id (date): gen wanted=1 if nlest2==1 & spinal_cord==1
      Kind regards,
      Carlo
      (StataNow 18.5)

      Comment


      • #4
        Two solutions depending on the rules -- there are yet others!

        Code:
        * must match in same observation 
        gen wanted1 = nlest2==1 & spinal_cord==1
        
        
        * must occur at least once for each id 
        egen any_nl = total(nlest2 == 1), by(id)
        egen any_sc = total(spinal_cord == 1), by(id)
        gen wanted2  = any_nl & any_sc

        Comment


        • #5
          Thank you so much !! Carlo and Nick.

          It doesn't end up working well for me.
          I'm sure I haven't explained myself clearly.

          1.-I need to identify the patients who throughout their follow-up the variable nlest2 and spinal_cord have a value = 1

          2.-If the patient has had nlest2 > 1 & spinal_cord =1
          3.-If the patient has had nlest2 = 1 & spinal_cord > 1
          4.-If the patient has had nlest2 = 1 & spinal_cord = 1


          clear
          input str11 id float(date previous_date) byte(nlest2 spinal_cord) float time
          "10005472" 19015 . 1 1 1
          "10013807" 22733 22559 10 . 1
          "10019101" . . . . 1
          "10020170" 18590 . 1 1 1
          "10020777" 17855 . 1 1 1
          "10020777" 17981 . 1 1 2
          "10064682" . . . . 1
          "10067748" 21833 . 10 . 1
          "10067748" 21962 21833 10 3 2
          "10067748" 22098 . 10 . 3
          "10067748" 22174 22098 . 4 4
          "10087618" 14741 . 7 1 1
          "10092188" 22717 22671 6 . 1
          "10116966" . . . . 1
          "10125008" 16461 . . . 1
          "10166894" . . . . 1
          "101797" . . . . 1
          "10179953" . . . . 1
          "10203595" 17774 . 10 3 1
          "10239623" 15756 . 10 . 1
          "10269479" 14347 . 10 2 1
          "10279987" 15275 . 10 . 1
          "10284142" . . . . 1
          "10301195" 16209 . . . 1
          "10309749" . . . . 1
          "10329252" 22027 . 10 1 1
          "10369688" 18241 . 10 1 1
          "10380065" . . . . 1
          "10427832" 17974 . 9 1 1
          "10430583" 17960 . 10 1 1
          "10443903" 20557 20457 2 1 1
          "10443903" 20557 . 2 1 2
          "10446691" 13724 . 10 1 1
          "10455777" 17231 . 5 2 1
          "10461822" 18787 . 1 . 1
          "10474520" 17245 . 1 . 1
          "10490935" . . . . 1
          "10497933" 22479 . 10 . 1
          "10497933" 22573 22479 10 . 2
          "10497933" 22598 22573 10 . 3
          "10525421" 16713 . . . 1
          "10541670" . . . . 1
          "10543947" . . . . 1
          "10544296" 18172 . 1 1 1
          "10552683" . . . . 1
          "10560658" 21461 . . 1 1
          "10582578" 15596 . 10 . 1
          "10660897" 18110 . 6 1 1
          "10715060" 14663 . 7 1 1
          "10718399" 17165 . 10 . 1
          "10739912" 13859 . 2 1 1
          "10801417" 17108 . 10 . 1
          "10818973" 18899 . 5 . 1
          "10821980" 20626 . 2 . 1
          "10833536" 21546 . 1 . 1
          "10833536" 21614 21546 . 1 2
          "10836550" 13781 . 8 2 1
          "10844214" . . . . 1
          "10863990" . . . . 1
          "10875123" 14910 . 10 1 1
          "109002" . . . . 1
          "10909624" 20032 . 10 4 1
          "10913259" 21579 . 10 3 1
          "10928171" 15957 . 10 . 1
          "10939267" 16762 . . . 1
          "10939789" 18084 . 10 2 1
          "10939789" 18158 18074 10 1 2
          "10939789" 18158 . 10 1 3
          "10943946" 16007 . . . 1
          "10960628" 13107 . 9 1 1
          "10980061" 17107 . 1 . 1
          "10980061" 17206 . 3 . 2
          "10981293" 12849 . 10 1 1
          "109834" 13048 . 1 1 1
          "11020459" . . . . 1
          "110216" 15524 . . . 1
          "11042733" 19850 . 1 1 1
          "11081919" . . . . 1
          "11091023" 16134 . . . 1
          "11097546" 19148 . 5 1 1
          "11134048" . . . . 1
          "11140827" 18191 18093 1 2 1
          "11140827" 18191 . 1 2 2
          "11148755" 22846 . 10 2 1
          "11163053" . . . . 1
          "11337630" 19997 . 10 4 1
          "11376065" 17804 . 1 1 1
          "11381717" 14216 . 1 1 1
          "11390176" 16189 . . . 1
          "11391472" 14500 . 6 1 1
          "11393448" 16960 . . . 1
          "11414155" 13283 . 8 1 1
          "11437706" 19934 . 10 3 1
          "11438363" 16280 . 10 . 1
          "11452213" 14694 . 10 1 1
          "11456798" 13639 . 4 . 1
          "11456798" 13670 . 1 . 2
          "11462380" 15349 . . . 1
          "11485804" . . . . 1
          "11497452" 15853 . 10 . 1
          end
          format %dD_m_CY date
          format %dD_m_CY previous_date

          Comment


          • #6
            Sorry, still ambiguous to me. The question is whether you want results observation or observation or for each patient. If the latter, the conditions 2 3 4 could each apply at different times.

            Comment


            • #7
              Augusto:
              I'm not clear whether conditions 2,3,4 should appear before condition 1 during follow-up (for patients having more than one observation).
              Kind regards,
              Carlo
              (StataNow 18.5)

              Comment


              • #8
                Yes, it is for each patient.

                1.-Identify the patients who throughout their follow-up the 2 variables take the value 1.

                2.-Identify patients who at some point during follow-up nlest2 is > 1 and spinal_cord =1

                3.-Identify patients who at some point during follow-up nlest2 is = 1 and spinal_cord > 1

                4.- Identify patients who have more than one measurement in spinal_cord to know if they have more than one MRI during follow-up

                Comment


                • #9
                  How are missing values supposed to be handled in applying these rules. For example, if a patient always has nlest2 == 1 and spinal_cord == 1 whenever these are non-missing, but there are some observations where one or both of these variables has a missing value, how is that person classified under rule 1. Similar issues arise for rules 2 and 3.

                  With regard to rule 4, do you mean more than one observation with a non-missing value for spinal_cord? Or do you mean that there are at least two different values of spinal cord--and, again, if this is the case, do missing values count as "different?"

                  Comment


                  • #10
                    You're right, Clyde.

                    I have to classify it as having data in one variable and missing in the other. Thank you very much best regards

                    Comment


                    • #11
                      I don't understand your response in #10. So I'm going to give you code based on some assumptions:
                      1. Misssing values cannot be ignored. So with regard to your first request, if all non-missing observations have both nlest2 and spinal_cord == 1 but there are also observations with missing values, then this variable will be coded zero, not one.
                      2. Missing values do not count as > 1. In order to meet criteria 2 or 3 in your request, the value of nlest2 or spinal_cord must be an actual non-missing number > 1.
                      3. I interpret your fourth request as asking for the number of non-missing entries for spinal_cord. The entries may or may not be the same numbers.

                      Code:
                      by id, sort: egen wanted1 = min(nlest2 == 1 & spinal_cord == 1)
                      by id: egen wanted2 = max(inrange(nlest2, 2, .) & spinal_cord == 1)
                      by id: egen wanted3 = max(nlest2 == 1 & inrange(spinal_cord, 2, .))
                      by id: egen wanted4 = count(spinal_cord)
                      replace wanted4 = inrange(wanted4, 2, .)
                      Try this and see if it is what you want. If it isn't, post back with new example data showing where the code produces unwanted results.

                      Comment

                      Working...
                      X