Announcement

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

  • identifying follow-up dates closest to a certain value

    Hello.

    I have a dataset with multiple follow-up dates (fu1, fu2 etc.) and corresponding morbidity scores (morb_a1, morb_b1, morb_a2, morb_b2 etc).

    I seek to identify the follow-up dates closest to certain time points after start of radiotherapy (RTstart) and very importantly their corresponding morbidity scores. The time points are 3, 6, 12, 24, 36, 48 and 60 months.
    If the follow-up date closest to this time point has a missing value for its corresponding morbidity, I wish to identify the second-nearet follow-up date and its corresponding morbidity score and so forth.
    The format of my follow-up dates are %tdnn/dd/CCYY.

    id RTstart fu1 morb_a1 morb_b1 fu2 morb_a2 morb_b2 fu3 morb_a3 morb_b3


    Thanks a lot in advance,

    Line.

  • #2
    This sounds to me like a minimum across variables in rows (observations). The egen function rowmin() helps but not with all of what i think you want.

    As for which date qualifies, there is a systematic discussion at https://www.stata-journal.com/articl...ticle=pr0046_1 but if that is behind a paywall as far as you are concerned a basic method follows (invented data, in the absence of a concrete data example as requested at FAQ Advice #12):

    Code:
    clear 
    input fu1 fu2 fu3 score1 score2 score3 
    .  22000 22030 . 42 666 
    21000 21500 22000 12 34 45 
    end 
    
    gen score_wanted = .
    gen fu_wanted = . 
    gen which_wanted = . 
    
    quietly forval j = 1/3 { 
        replace fu_wanted = min(fu_wanted, fu`j') 
        replace score_wanted = score`j' if fu_wanted == fu`j'
        replace which_wanted = `j' if fu_wanted == fu`j'
    }
    
    list 
    
         +-----------------------------------------------------------------------------------+
         |   fu1     fu2     fu3   score1   score2   score3   score_~d   fu_wan~d   which_~d |
         |-----------------------------------------------------------------------------------|
      1. |     .   22000   22030        .       42      666         42      22000          2 |
      2. | 21000   21500   22000       12       34       45         12      21000          1 |
         +-----------------------------------------------------------------------------------+

    Comment

    Working...
    X