Conditional Variable Recode Into Different Variable

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

Conditional Variable Recode Into Different Variable

Jim Moffitt
I want to recode an existing varible named CrsCount1_96 into a new
variable that doesn't yet exist in my datafile. I'd like to name the new
variable CrsCount1_96Revised.
If another existing variable in the dataset (named q_1.89) contains a
value of 89, I'd like CrsCount1_96Revised to equal CrsCount1_96 + 1.
If q_1.89 does not equal 89, I'd like CrsCount1_96Revised to equal
CrsCount1_96.
Can anyone show me how to do this?
Thanks.
Jim
Reply | Threaded
Open this post in threaded view
|

Re: Conditional Variable Recode Into Different Variable

Marta García-Granero
Hi Jim

Sunday, January 7, 2007, 10:53:35 PM, You wrote:

JM> I want to recode an existing varible named CrsCount1_96 into a new
JM> variable that doesn't yet exist in my datafile. I'd like to name the new
JM> variable CrsCount1_96Revised.
JM> If another existing variable in the dataset (named q_1.89) contains a
JM> value of 89, I'd like CrsCount1_96Revised to equal CrsCount1_96 + 1.
JM> If q_1.89 does not equal 89, I'd like CrsCount1_96Revised to equal
JM> CrsCount1_96.

(Untested):

DO IF (q_1.89 = 89).
. COMPUTE CrsCount1_96Revised = CrsCount1_96+1.
ELSE.
. COMPUTE CrsCount1_96Revised = CrsCount1_96.
END IF.

EXE. /* (only if you want to see the results inmediately) *.

Regards,
Marta
Reply | Threaded
Open this post in threaded view
|

Re: Conditional Variable Recode Into Different Variable

Jim Moffitt
Thanks, Marta.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Marta García-Granero
Sent: Sunday, January 07, 2007 4:54 PM
To: [hidden email]
Subject: Re: Conditional Variable Recode Into Different Variable

Hi Jim

Sunday, January 7, 2007, 10:53:35 PM, You wrote:

JM> I want to recode an existing varible named CrsCount1_96 into a new
JM> variable that doesn't yet exist in my datafile. I'd like to name the
JM> new variable CrsCount1_96Revised.
JM> If another existing variable in the dataset (named q_1.89) contains
JM> a value of 89, I'd like CrsCount1_96Revised to equal CrsCount1_96 + 1.
JM> If q_1.89 does not equal 89, I'd like CrsCount1_96Revised to equal
JM> CrsCount1_96.

(Untested):

DO IF (q_1.89 = 89).
. COMPUTE CrsCount1_96Revised = CrsCount1_96+1.
ELSE.
. COMPUTE CrsCount1_96Revised = CrsCount1_96.
END IF.

EXE. /* (only if you want to see the results inmediately) *.

Regards,
Marta
Reply | Threaded
Open this post in threaded view
|

Re: Conditional Variable Recode Into Different Variable

Judith Saebel
In reply to this post by Jim Moffitt
do if q_1.89 eq 89.
compute CrsCount1_96Revised = CrsCount1_96 + 1.
end if.

do if q_1.89 ne 89.
compute CrsCount1_96Revised = CrsCount1_96.
end if.



-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Jim Moffitt
Sent: Monday, 8 January 2007 08:24
To: [hidden email]
Subject: Conditional Variable Recode Into Different Variable

I want to recode an existing varible named CrsCount1_96 into a new
variable that doesn't yet exist in my datafile. I'd like to name the new
variable CrsCount1_96Revised.
If another existing variable in the dataset (named q_1.89) contains a
value of 89, I'd like CrsCount1_96Revised to equal CrsCount1_96 + 1.
If q_1.89 does not equal 89, I'd like CrsCount1_96Revised to equal
CrsCount1_96.
Can anyone show me how to do this?
Thanks.
Jim
Reply | Threaded
Open this post in threaded view
|

Re: Conditional Variable Recode into Different Variable

Leslie Horst
In reply to this post by Jim Moffitt
To Marta' solution I would only add that if there are any missing data
in the variable q_1.89, you will need to deal with that situation first,
and then go on into the rest of the do if.  I suggest something like:

(untested)

Do if (sysmis(q_1.89)).
Compute CrsCount1_96 = whatever it should be, under these circumstances.
Else if (q_1.89 = 89).
. COMPUTE CrsCount1_96Revised = CrsCount1_96+1.
ELSE.
. COMPUTE CrsCount1_96Revised = CrsCount1_96.
END IF.

EXE. /* (only if you want to see the results inmediately) *.


Without this, your new variable CrsCoun1_96Revised will be system
missing for every instance in which q_1.89 is missing.  That may be OK
with you, but it should be a conscious choice.  Also, if there are
missing data in CrsCount1_96 you need to address that as well.  I would
assume that under that circumstance you would like the revised variable
also to be system missing.  In general, if you're being really careful,
you can set the new variable to something like -99 in any case of
missing data, check frequencies to make sure every case has gone through
the do if where it should, and then set -99 to the user missing value.
Not so important in a simple do if like this one, but very helpful in
more complex ones.

Leslie Horst, Ph.D.
Senior Consultant
Maguire Associates, Inc.
5 Concord Farms
555 Virginia Rd.
Concord, MA  01740
978-371-3771 x297
[hidden email]



-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Automatic digest processor
Sent: Monday, January 08, 2007 12:04 AM
To: Recipients of SPSSX-L digests
Subject: SPSSX-L Digest - 6 Jan 2007 to 7 Jan 2007 (#2007-8)

There are 4 messages totalling 133 lines in this issue.

Topics of the day:

  1. Conditional Variable Recode Into Different Variable (4)

----------------------------------------------------------------------

Date:    Sun, 7 Jan 2007 15:53:35 -0600
From:    Jim Moffitt <[hidden email]>
Subject: Conditional Variable Recode Into Different Variable

I want to recode an existing varible named CrsCount1_96 into a new
variable that doesn't yet exist in my datafile. I'd like to name the new
variable CrsCount1_96Revised.
If another existing variable in the dataset (named q_1.89) contains a
value of 89, I'd like CrsCount1_96Revised to equal CrsCount1_96 + 1.
If q_1.89 does not equal 89, I'd like CrsCount1_96Revised to equal
CrsCount1_96.
Can anyone show me how to do this?
Thanks.
Jim

------------------------------

Date:    Sun, 7 Jan 2007 23:53:32 +0100
From:    =?ISO-8859-15?B?TWFydGEgR2FyY+1hLUdyYW5lcm8=?=
<[hidden email]>
Subject: Re: Conditional Variable Recode Into Different Variable

Hi Jim

Sunday, January 7, 2007, 10:53:35 PM, You wrote:

JM> I want to recode an existing varible named CrsCount1_96 into a new
JM> variable that doesn't yet exist in my datafile. I'd like to name the
new
JM> variable CrsCount1_96Revised.
JM> If another existing variable in the dataset (named q_1.89) contains
a
JM> value of 89, I'd like CrsCount1_96Revised to equal CrsCount1_96 + 1.
JM> If q_1.89 does not equal 89, I'd like CrsCount1_96Revised to equal
JM> CrsCount1_96.

(Untested):

DO IF (q_1.89 = 89).
. COMPUTE CrsCount1_96Revised = CrsCount1_96+1.
ELSE.
. COMPUTE CrsCount1_96Revised = CrsCount1_96.
END IF.

EXE. /* (only if you want to see the results inmediately) *.

Regards,
Marta

------------------------------

**********************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Conditional Variable Recode into Different Variable

Jim Moffitt
Excellent point, Leslie. Thank you.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Leslie Horst
Sent: Monday, January 08, 2007 9:23 AM
To: [hidden email]
Subject: Re: Conditional Variable Recode into Different Variable

To Marta' solution I would only add that if there are any missing data
in the variable q_1.89, you will need to deal with that situation first,
and then go on into the rest of the do if.  I suggest something like:

(untested)

Do if (sysmis(q_1.89)).
Compute CrsCount1_96 = whatever it should be, under these circumstances.
Else if (q_1.89 = 89).
. COMPUTE CrsCount1_96Revised = CrsCount1_96+1.
ELSE.
. COMPUTE CrsCount1_96Revised = CrsCount1_96.
END IF.

EXE. /* (only if you want to see the results inmediately) *.


Without this, your new variable CrsCoun1_96Revised will be system
missing for every instance in which q_1.89 is missing.  That may be OK
with you, but it should be a conscious choice.  Also, if there are
missing data in CrsCount1_96 you need to address that as well.  I would
assume that under that circumstance you would like the revised variable
also to be system missing.  In general, if you're being really careful,
you can set the new variable to something like -99 in any case of
missing data, check frequencies to make sure every case has gone through
the do if where it should, and then set -99 to the user missing value.
Not so important in a simple do if like this one, but very helpful in
more complex ones.

Leslie Horst, Ph.D.
Senior Consultant
Maguire Associates, Inc.
5 Concord Farms
555 Virginia Rd.
Concord, MA  01740
978-371-3771 x297
[hidden email]



-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Automatic digest processor
Sent: Monday, January 08, 2007 12:04 AM
To: Recipients of SPSSX-L digests
Subject: SPSSX-L Digest - 6 Jan 2007 to 7 Jan 2007 (#2007-8)

There are 4 messages totalling 133 lines in this issue.

Topics of the day:

  1. Conditional Variable Recode Into Different Variable (4)

----------------------------------------------------------------------

Date:    Sun, 7 Jan 2007 15:53:35 -0600
From:    Jim Moffitt <[hidden email]>
Subject: Conditional Variable Recode Into Different Variable

I want to recode an existing varible named CrsCount1_96 into a new
variable that doesn't yet exist in my datafile. I'd like to name the new
variable CrsCount1_96Revised.
If another existing variable in the dataset (named q_1.89) contains a
value of 89, I'd like CrsCount1_96Revised to equal CrsCount1_96 + 1.
If q_1.89 does not equal 89, I'd like CrsCount1_96Revised to equal
CrsCount1_96.
Can anyone show me how to do this?
Thanks.
Jim

------------------------------

Date:    Sun, 7 Jan 2007 23:53:32 +0100
From:    =?ISO-8859-15?B?TWFydGEgR2FyY+1hLUdyYW5lcm8=?=
<[hidden email]>
Subject: Re: Conditional Variable Recode Into Different Variable

Hi Jim

Sunday, January 7, 2007, 10:53:35 PM, You wrote:

JM> I want to recode an existing varible named CrsCount1_96 into a new
JM> variable that doesn't yet exist in my datafile. I'd like to name the
new
JM> variable CrsCount1_96Revised.
JM> If another existing variable in the dataset (named q_1.89) contains
a
JM> value of 89, I'd like CrsCount1_96Revised to equal CrsCount1_96 + 1.
JM> If q_1.89 does not equal 89, I'd like CrsCount1_96Revised to equal
JM> CrsCount1_96.

(Untested):

DO IF (q_1.89 = 89).
. COMPUTE CrsCount1_96Revised = CrsCount1_96+1.
ELSE.
. COMPUTE CrsCount1_96Revised = CrsCount1_96.
END IF.

EXE. /* (only if you want to see the results inmediately) *.

Regards,
Marta

------------------------------

**********************************************************