Announcement

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

  • Creating redcap_repeat_instance variable for dataset to be uploaded to REDCap database

    I would like to know how to generate a variable which contains in numeric sequence, the number of repeated observations for each record_id, for example:

    If there are 3 surveys completed by a patient and each survey is one observation in a stata dataset, how do I create and add values (sequence of when completed) to a variable for each observation per patient? So PatientA fills out the same survey on 1st Jan, 2nd March and 20th July. How to I have a 'repeat_instance' variable that will have the value '1' for that patient's survey on 1st Jan, a '2' for the survey completed 2nd March, and a '3' for the survey completed 20th July? I would then want the numbering to start again from '1' for PatientB and so on.

  • #2
    You can do it with this code:
    Code:
    by patient (date), sort: gen int redcap_repeat_instance = _n
    Evidently, you must adapt this code by replacing "patient" and "date" with the actual names of the variables identifying the patients and the dates in your data set.

    Also, the date variable MUST be a Stata internal format numerical date variable. If it is a string variable that looks to human eyes like a date, this code will give incorrect results. If you are not familiar with Stata internal format numerical date variables, you'll need to invest some time learning about them. Start by reading the -help datetime- file.

    Comment


    • #3
      Thank you Clyde! This works perfectly. Much appreciated.

      Comment

      Working...
      X