Restructuring variables

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

Restructuring variables

Hashmi, Syed S
Hi all,

I've got this dataset which has a list of illnesses that individuals got
over a period of time and for how long they had it.  The duration of
illness is coded in two columns - one is a numeric variable ("illcount"),
and the other is a categorical variable ("illunit") where 1=days, 2=weeks,
3=months.  Therefore, a person can have the illness for X number of days,
weeks or months, where X is the numeric value of the variable count.

To help in my analysis, I wanted to convert them all to days, which is
easy enough to do.  The trouble is that there are up to six separate
variables for each illness. For example, if I'm talking about the flu,
there will be 6 pairs of variables - flucount1, fluunit1; flucount2,
fluunit2; flucount3, fluunit3; flucount4, fluunit4; flucount5, fluunit5;
and flucount6, fluunit6. Plus this format is spread out over 7 different
illnesses.

Converting each of them to days one after another is tedious and I was
hoping that I could have some kind of macro that would handle the task.
I'll probably have to create 7 different macros, one for each illness.

I was thinking that one way to do this would be to tell SPSS to multiply
illcount_x by 1, 7 or 30 depending on the value of illunit_x, where _x = 1
to 6.  I'm not sure what the syntax should be for this and was hoping that
someone here could help me with it.

Thanks a heap in advance.
Reply | Threaded
Open this post in threaded view
|

Re: Restructuring variables

Marks, Jim
Not tested:


DO REPEAT x= flucount1 flucount2 flucount3 flucount4 flucount5 flucount6
flucount7
   /y = fludays1 TO fludays7
  /z = fluunit1 fluunit2 fluunit3 fluunit4 fluunit5 fluunit6 fluunit7
.

DO IF  z = 1.
COMPUTE y = z.
ELSE IF z = 2.
COMPUTE y = z*7.
ELSE IF z = 3.
COMPUTE y = z*30.
END IF.

END REPEAT.

Create a similar structure for other variable sets.

If the files is organized
        flucount1 flucount2...

Instead of
        flucount1 fluunit1 flucount2 fluunit2

You could use the flucount1 TO flucount7 convention. Otherwise type out
all the sets separately.

cheers
--jim



-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Shahrukh Hashmi
Sent: Tuesday, June 12, 2007 10:59 AM
To: [hidden email]
Subject: Restructuring variables

Hi all,

I've got this dataset which has a list of illnesses that individuals got
over a period of time and for how long they had it.  The duration of
illness is coded in two columns - one is a numeric variable
("illcount"), and the other is a categorical variable ("illunit") where
1=days, 2=weeks, 3=months.  Therefore, a person can have the illness for
X number of days, weeks or months, where X is the numeric value of the
variable count.

To help in my analysis, I wanted to convert them all to days, which is
easy enough to do.  The trouble is that there are up to six separate
variables for each illness. For example, if I'm talking about the flu,
there will be 6 pairs of variables - flucount1, fluunit1; flucount2,
fluunit2; flucount3, fluunit3; flucount4, fluunit4; flucount5, fluunit5;
and flucount6, fluunit6. Plus this format is spread out over 7 different
illnesses.

Converting each of them to days one after another is tedious and I was
hoping that I could have some kind of macro that would handle the task.
I'll probably have to create 7 different macros, one for each illness.

I was thinking that one way to do this would be to tell SPSS to multiply
illcount_x by 1, 7 or 30 depending on the value of illunit_x, where _x =
1 to 6.  I'm not sure what the syntax should be for this and was hoping
that someone here could help me with it.

Thanks a heap in advance.