How can I transpose REDCap longitudinal data in SPSS or R?

Q: A data file exported from a REDCap longitudinal project may contain many data rows for a given record. I wonder if someone has created a generic routine or program/procedure that processes such a file to generate a new file having one data row for all records including needed variable relabeling?

You can reshape data via stats packages such as: SPSS's casestovars command, or the Reshape package in R.

Here's a link for an SPSS example: http://www.ats.ucla.edu/stat/spss/modules/reshapew115.htm

SPSS Scripts contributed by Vivian Haime:

In order to take long data files, from data collected at multiple time points per participants, and reshape them into wide form, I followed these steps:

FROM THE TOOLBAR: Data→Restructure→Restructure selected cases into variables→Identifier_variable(s): Subject ID #; Index_variable(s): REDCap_Event→Yes, data will be sorted by identifier and index variables→group by original variable→FINISH

SYNTAX:

 SORT CASES BY subject_id redcap_event_name. CASESTOVARS 
 /ID=subject_id
 /INDEX=redcap_event_name
 /GROUPBY=VARIABLE.

You may have to rename the variables afterwards.

 

More help for SPSS: http://www.ats.ucla.edu/stat/spss/modules/reshapew115.htm

 

 


Related articles