Announcement

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

  • Looping through values and comparing

    Hi

    I am stuck with my data analysis. I am trying to calculate cumulative birth rates and I am not sure on how to solve the problem. I have made a small example in the table below where I have 3 patients (Patient 1,2 and 3). The patients are part of an IVF treatment cycle where after the IVF procedure they either receive a fresh embryo transfer (FreshORfreeze = 0) or they recieve a frozen embryo (FreshORfreeze = 1). The cycle number represents that the frozen embryos came from a specific IVF cycle (so patient 1 for example have in total 3 embryos put back (1 fresh and 2 frozen) all from the same IVF cycle.
    Patient Cycle FreshORfreeze Pregnant
    1 101 0 0
    1 101 1 0
    1 101 1 1
    2 102 0 0
    2 102 1 0
    3 103 0 1
    What I want to achieve is to find out if patient 1,2 and 3 got pregnant after all the cycles are done. So basically I want to have patients nr 1 = pregnant, patient nr 2 = not pregnant, patients number 3 = pregnant. So in this case go from 6 observations down to 3.
    I am guessing that I have to somehow loop through the cycle numbers?

    Any help would be greately appreciated

    Cheers

  • #2
    to keep the largest value of Pregnant by Patient,
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte Patient int Cycle byte(FreshORfreeze Pregnant)
    1 101 0 0
    1 101 1 0
    1 101 1 1
    2 102 0 0
    2 102 1 0
    3 103 0 1
    end
    
    by Patient (Pregnant), sort: keep if _n==_N
    alternatively,
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte Patient int Cycle byte(FreshORfreeze Pregnant)
    1 101 0 0
    1 101 1 0
    1 101 1 1
    2 102 0 0
    2 102 1 0
    3 103 0 1
    end
    
    collapse (max) Pregnant, by(Patient)

    Comment

    Working...
    X