complex restructure

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

complex restructure

alex mcveigh
Dear all, this is my first post to the forum. I searched for a similar query but couldn’t find. I am using SPSS v20 on windows 7 32-bit.
I'm a postgrad medical researcher with some raw blood pressure (SBP) data in long format which needs reshaping to allow me to generate new variables to mixed-effects model.  Extract of the data is here:
BP.csv
BP


Subjects (ID) had SBP measured both before and after a treatment (PrePost_T,  1=Pre-treatment, 2=Post-treatment) on several dates (Treat_date) usually 2-3 days apart. Data are unbalanced with varying number of observations per ID. My main interest is in the change in SBP on the same Treat_date. Ideally I need the Pre-Treatment BP in a column adjacent to the Post-treatment BP column.  I tried using a variety of setups in CASESTOVARS using a combination of ID, Treat_date and PrePost_T to make a unique INDEX.

SORT CASES BY ID Treat_date PrePost_T.
CASESTOVARS
   /INDEX=Treat_date PrePost_T
  /GROUPBY=VARIABLE.
This led to either an error message saying my observations were not unique or generating 1 row per ID with all observations as new variables in wide format. My questions are:
1. I suspect there is an alternative method/syntax to separate my pre and post-treatment BPs in column PrePost_T for each ID but seems beyond my lateral thinking or SPSS knowledge. Can anyone help?
2. Assuming CASESTOVARS is the wrong approach, I would still find it useful in future to create a unique index from long format data using a combination of ID and 2 variables. Is this possible?

My thanks in advance
Alex McVeigh

 
Reply | Threaded
Open this post in threaded view
|

Re: complex restructure

Bruce Weaver
Administrator
I assume you still want a long file structure, and that you want to use pre-treatment BP as a time-dependent explanatory variable, and post-treatment BP as the outcome variable.  

How about this (untested)?

SORT CASES BY ID Treat_date PrePost_T.
IF (PrePost_T EQ 2) and (ID EQ LAG(ID)) BP0 = LAG(BP).
SELECT IF (PrePost_T EQ 2).
EXECUTE.
RENAME VARIABLES (BP = BP1).
VARIABLE LABELS
 BP0 "Pre-treatment BP"
 BP1 "Post-treatement BP"
.

HTH.

alex mcveigh wrote
Dear all, this is my first post to the forum. I searched for a similar query but couldn’t find. I am using SPSS v20 on windows 7 32-bit.
I'm a postgrad medical researcher with some raw blood pressure (SBP) data in long format which needs reshaping to allow me to generate new variables to mixed-effects model.  Extract of the data is here:
BP.csv
BP


Subjects (ID) had SBP measured both before and after a treatment (PrePost_T,  1=Pre-treatment, 2=Post-treatment) on several dates (Treat_date) usually 2-3 days apart. Data are unbalanced with varying number of observations per ID. My main interest is in the change in SBP on the same Treat_date. Ideally I need the Pre-Treatment BP in a column adjacent to the Post-treatment BP column.  I tried using a variety of setups in CASESTOVARS using a combination of ID, Treat_date and PrePost_T to make a unique INDEX.

SORT CASES BY ID Treat_date PrePost_T.
CASESTOVARS
   /INDEX=Treat_date PrePost_T
  /GROUPBY=VARIABLE.
This led to either an error message saying my observations were not unique or generating 1 row per ID with all observations as new variables in wide format. My questions are:
1. I suspect there is an alternative method/syntax to separate my pre and post-treatment BPs in column PrePost_T for each ID but seems beyond my lateral thinking or SPSS knowledge. Can anyone help?
2. Assuming CASESTOVARS is the wrong approach, I would still find it useful in future to create a unique index from long format data using a combination of ID and 2 variables. Is this possible?

My thanks in advance
Alex McVeigh
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: complex restructure

alex mcveigh
thanks this worked very nicely.