Announcement

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

  • Missing values and panel data

    Hi,

    I am currently working on a database with repeated values over time. This database is as follows:


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long ctrpat byte(visite A_SCMMSE)
    10005001 0 28
    10005001 1  .
    10005001 2 30
    10005001 3  .
    10005001 4 30
    10005001 5  .
    10005001 6 30
    10005002 0 30
    10005002 1  .
    10005002 2 29
    10005002 3  .
    10005002 4 30
    10005002 5  .
    10005002 6 30
    10005003 0 25
    10005003 1  .
    10005003 2 27
    10005003 3  .
    10005003 4 25
    10005003 5  .
    10005003 6 26
    10005004 0 30
    10005004 1  .
    10005004 2 29
    10005004 3  .
    10005004 4 30
    10005004 5  .
    10005004 6 30
    10007001 0 30
    10007001 1  .
    10007002 0 30
    10007003 0  .
    10010001 0 30
    10010001 1  .
    10010001 2  .
    10010002 0  .
    10010003 0  .
    10010003 1  .
    10010004 0  .
    10010004 1  .
    10015001 0  .
    10015001 1  .
    10015001 2  .
    10015001 3  .
    10015001 4 19
    10015001 5  .
    10015001 6 12
    10015002 0  .
    10015002 1  .
    10015002 2  .
    end
    ctrpat is the identification number for each subject
    visite is the visit number over time (patients were followed 7 times)
    A_SCMMSE is the cognitive score at each follow-up visit (mainly at V0, 2, 4 and 6)

    I would like to create a new cognitive variable = to the delta of cognition between the first one evaluation of cognition and the last one for each patient. Thus, mainly between the 6th and the baseline visit but due to missing values or patients sometimes having visits at v1, v3, and maybe v5, it can change from one subject to another one.

    Thank you very for your help +++

    Best regards,

    Pierre




  • #2
    I think this will give you what you want:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long ctrpat byte(visite A_SCMMSE)
    10005001 0 28
    10005001 1  .
    10005001 2 30
    10005001 3  .
    10005001 4 30
    10005001 5  .
    10005001 6 30
    10005002 0 30
    10005002 1  .
    10005002 2 29
    10005002 3  .
    10005002 4 30
    10005002 5  .
    10005002 6 30
    10005003 0 25
    10005003 1  .
    10005003 2 27
    10005003 3  .
    10005003 4 25
    10005003 5  .
    10005003 6 26
    10005004 0 30
    10005004 1  .
    10005004 2 29
    10005004 3  .
    10005004 4 30
    10005004 5  .
    10005004 6 30
    10007001 0 30
    10007001 1  .
    10007002 0 30
    10007003 0  .
    10010001 0 30
    10010001 1  .
    10010001 2  .
    10010002 0  .
    10010003 0  .
    10010003 1  .
    10010004 0  .
    10010004 1  .
    10015001 0  .
    10015001 1  .
    10015001 2  .
    10015001 3  .
    10015001 4 19
    10015001 5  .
    10015001 6 12
    10015002 0  .
    10015002 1  .
    10015002 2  .
    end
    
    gen missing_score = missing(A_SCMMSE)
    by ctrpat missing_score (visite), sort:  gen delta = A_SCMMSE[_N] - A_SCMMSE[1]
    by ctrpat (delta), sort: replace delta = delta[1] if missing(delta)
    sort ctrpat visite
    drop missing_score
    Note: There are some instances in the data where there is only one non-missing value of A_SCMMSE. In this situation, the code above calculates the change as 0. You might, however, prefer not to calculate a change when there is only one observation. If so, just add -if _N > 1- to the -by ctrpat missing_score (visite), sort: gen delta = ...- command.

    Comment


    • #3
      Thank you so much for your valuable help. This is perfectly what I was looking for and it will be very helpful for me also in other types of situations.

      Have a nice day,

      Best regards,

      Pierre

      Comment

      Working...
      X