Wide to Long with unequal number of repeated measurements SPSS

Viewed 196

I want to Reconstruct dataset from wide format to long format for analysis in mixed models. Some variables have 0M, 3M, 6M, 9M, 12M repeated measurements every 3 months for a 12M follow-up, and some have 12 measurements one every month. When I use VARTOCASES, how do I fill in the sub-command index? If I record (5) it is not suitable for repeated measurements every month and so on if I register (12) it will not be suitable for measurements every 3 months. What do you suggest?

VARSTOCASES
    / make WEIGHT from WEIGHT0M WEIGHT3M WEIGHT6M WEIGHT9M WEIGHT12M
    / make HB from HB1 to HB12
    / index = TIME (5)
    / keep = ID.
1 Answers

First you have to take care of the imbalance between the two variable groups - varstocases won't work at all until they are balanced (you can't have two /make ... from commands with different numbers of variables). One way to balance them could be to create dummy variables to fill the gaps.

A couple of notes before the code:

  1. Variable names like WEIGHT0M WEIGHT3M WEIGHT6M ... don't work as well with the TO keyword, so in the syntax below I create a completely new series and "import" the values from the old variables.
  2. It seems to be you actually have 13 data points and not 12 - since variable WEIGHT0M represents point 0M which isn't represented in the HB1 to HB12 series - so we need to create a dummy for that too.
compute WEIGHTM0=WEIGHT0M.
vector WEIGHTM(12).
do repeat /nw=WEIGHTM3 WEIGHTM6 WEIGHTM9 WEIGHTM12 /orig=WEIGHT3M WEIGHT6M WEIGHT9M WEIGHT12M.
   compute nw=orig.
end repeat.
compute HB0=$sysmis.
    
VARSTOCASES
    / make WEIGHT from WEIGHTM0 to WEIGHTM12
    / make HB from HB0 to HB12
    / index = TIME (13).

This will end up with empty values in the WEIGHT column for time points 1,2,4,5 etc'. Alternatively you could choose to put values there, for example you could copy the value of point 0 to points 1, 2, the value of point 3 to points 4, 5 etc'. You can do it by extending the above loop, or you could use the following - after the varstocases:

sort cases by ID index.
if $casenum>1 and ID=lag(ID) and missing(WEIGHT) WEIGHT=lag(WEIGHT).
Related