Date: Thu, 5 Nov 1998 19:01:36 -0600
Reply-To: "Matheson, David" <davidm@SPSS.COM>
Sender: "SPSSX(r) Discussion" <SPSSX-L@UGA.CC.UGA.EDU>
From: "Matheson, David" <davidm@SPSS.COM>
Subject: Re: conditionally copying cases
I've pasted a sample job below that creates a new file where a case
which had k levels of care is now represented by k cases,
each of which only has 1 level of care and the value of department (dept)
corresponds to the level of care. I've used fewer variables than
you described: v1 to v3 stand in for the 25 survey variables
and there are only 4 level of care (LOC) variables: inpat, outpat, medic,
You'll need to change the LOOP and NUMERIC commands to reflect your 20 LOC
Also, I'm treating the LOC variables as numeric with values of 0 and 1.
If they're 'YES'/'NO' strings, you'll need to change the IF condition in the
to reflect this, change the NUMERIC command to a STRING and change the
Note that the new file is created with a single variable, LOCARE, that holds
level of care for that replication of the case. If you want 20 binary LOC
you'll need to open the new file and generate them. The second part of the
shows you how to do that.
* DEPART is the original department variable. A new var DEPT is
* used so that DEPART can be kept as a default for dept,
* should there be an LOC value that is not tied to a particular dept.
* STATUS and ID are assumed to exist in the file - STATUS as per
* Steve's description; ID to represent whatever patient ID might exist
* in the file.
vector levcar = inpat to detox .
loop locare = 1 to 4.
do if (levcar(locare) = 1) .
compute dept = depart .
if any(locare,1,3) dept = 24 .
if (locare = 2) dept = 26.
if (locare = 4) dept = 25.
xsave outfile = hospst2.sav /keep = id v1 to v3 status dept locare .
* if you want the new file to have level of care stored
* in a set of dichotomous variables, but with only one
* of this set equal to 1, do the following.
* You can drop locare when you save the file .
get file = hospst2.sav .
numeric inpat outpat medic detox (f6).
vector levcar = inpat to detox .
compute levcar(locare) = 1.
recode inpat to detox (missing = 0).
I would reinforce Rich's caveats about many tempting
analysis options that would be statistically unsound because of
the nonindependence of the observations in the new file.
Some other analyses, such as examining co-occurence of
certain levels of care, would only be possible in the original file
The syntax above does leave the original file intact.
I hope this helps.
SPSS Technical Support
> -----Original Message-----
> From: Richard F Ulrich [SMTP:wpilib+@PITT.EDU]
> Sent: Thursday, October 29, 1998 4:08 PM
> To: SPSSX-L@UGA.CC.UGA.EDU
> Subject: Re: conditionally copying cases
> Steve Lord (email@example.com) wrote:
> < stuff about data set >
> : Status (intake, anniversary, or discharge).
> : Department (24, 25, 26, 27).
> : Twenty other yes/no variables exist that designate a "level of care"
> : outpatient, inpatient, residential,...., detox). Most levels of care
> : correspond (but not always) to specific departments. (For example, an
> : inpatient level of care would be in Department 24. A medication level
> : care would also be in Department 24. A detox level of care would be in
> : Department 25.)
> : Each case may have several levels of care, but is only coded to a single
> : department. What I need to do is have a case for each level of care,
> : corresponding department, and Status.
> : Therefore, if I have a case in which a person is an "intake" (Status) to
> : Department 24 receiving care that is "inpatient", "detox", and
> : then I need to have two additional cases:
> : Intake, Dept. 25, and detox
> : Intake, Dept. 24, and medication
> - Are you SURE that you need to create duplicate lines in the file?
> You will create a dataset that is invalid for a number of
> statistical purposes, if you directly incorporate the new lines in
> the original dataset.
> On the other hand, if you put all the extra lines into a second file,
> and use "ADD FILES" when you want to use the augmented set, then you
> can have it both ways.
> Or, if you don't like that suggestion, you can create the file, and then
> the two together and save that; and keep a POINTER that says "extra".
> Anyhow: You need to know where the redundancy exists. The simple
> solution is use
> DO IF <conditional: extra line needed, of type AAA>
> COMPUTE <or recode, to make values what you need for AAA>
> < i.e., "level of care" and "department"
> XSAVE <name a file, for now >
> ELSE IF < second conditional >
> - It might take two runs, if you need to create TWO extra lines
> from one existing line. Then use ADD FILES.
> Rich Ulrich, biostatistician firstname.lastname@example.org
> http://www.pitt.edu/~wpilib/index.html Univ. of Pittsburgh