DO IF

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

DO IF

Will Daley
Hi... I'm a noobie - forgive me. I've got a dataset wherein I have a series
of variables that record first and second choices. The first and second
choices cannot be identical, but in a few cases they are. I'm trying to
figure what command syntax I would use to convert any duplicate values in
second choice variables into SYSMIS.

I'm thinking I would use either the "select if" or "do if" commands to
identify cases where the value in the second choice variable is identical to
the value in the first choice variable, but I'm not sure what command I
would use to complete the transformation of the duplicate values identified
in this way into SYSMIS.

Can anyone point me in the right direction?

Thanks very much!



--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: DO IF

88videos
Like this?


data list list
/id first_choice second_choice.
begin data.
1 1 2
2 2 3
3 3 4
4 1 4
5 2 2
end data.
execute.

do if first_choice = second_choice.
recode second_choice
(lo thru hi=SYSMIS).
end if.
execute.

list.



--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: DO IF

Rick Oliver
In reply to this post by Will Daley
If v2=v1 v2=$sysmis.

On Oct 1, 2017 7:08 AM, "Will Daley" <[hidden email]> wrote:
Hi... I'm a noobie - forgive me. I've got a dataset wherein I have a series
of variables that record first and second choices. The first and second
choices cannot be identical, but in a few cases they are. I'm trying to
figure what command syntax I would use to convert any duplicate values in
second choice variables into SYSMIS.

I'm thinking I would use either the "select if" or "do if" commands to
identify cases where the value in the second choice variable is identical to
the value in the first choice variable, but I'm not sure what command I
would use to complete the transformation of the duplicate values identified
in this way into SYSMIS.

Can anyone point me in the right direction?

Thanks very much!



--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: DO IF

Bruce Weaver
Administrator
In reply to this post by Will Daley
Rick Oliver has given you a simple solution:

IF v2 EQ v1 v2=$sysmis.

But when Art Kendall reads this, I'm sure he'll urge you to *not* use SYSMIS
in this situation.  You *know* why v2 is missing, so assign a user-defined
missing value (e.g. -999), and assign a value label to it.  

IF v2 EQ v1 v2 = -999.
MISSING VALUES v2 (-999).
ADD VALUE LABELS v2 -999 "Identical to v1, so assigned missing value".

If -999 is a legal value for v2, choose another value that is not.  

HTH.



Will Daley wrote

> Hi... I'm a noobie - forgive me. I've got a dataset wherein I have a
> series
> of variables that record first and second choices. The first and second
> choices cannot be identical, but in a few cases they are. I'm trying to
> figure what command syntax I would use to convert any duplicate values in
> second choice variables into SYSMIS.
>
> I'm thinking I would use either the "select if" or "do if" commands to
> identify cases where the value in the second choice variable is identical
> to
> the value in the first choice variable, but I'm not sure what command I
> would use to complete the transformation of the duplicate values
> identified
> in this way into SYSMIS.
>
> Can anyone point me in the right direction?
>
> Thanks very much!
>
>
>
> --
> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.
Reply | Threaded
Open this post in threaded view
|

Re: DO IF

Rick Oliver
I didn't go there because I sent the response from my phone. :)

On Oct 1, 2017 8:59 AM, "Bruce Weaver" <[hidden email]> wrote:
Rick Oliver has given you a simple solution:

IF v2 EQ v1 v2=$sysmis.

But when Art Kendall reads this, I'm sure he'll urge you to *not* use SYSMIS
in this situation.  You *know* why v2 is missing, so assign a user-defined
missing value (e.g. -999), and assign a value label to it.

IF v2 EQ v1 v2 = -999.
MISSING VALUES v2 (-999).
ADD VALUE LABELS v2 -999 "Identical to v1, so assigned missing value".

If -999 is a legal value for v2, choose another value that is not.

HTH.



Will Daley wrote
> Hi... I'm a noobie - forgive me. I've got a dataset wherein I have a
> series
> of variables that record first and second choices. The first and second
> choices cannot be identical, but in a few cases they are. I'm trying to
> figure what command syntax I would use to convert any duplicate values in
> second choice variables into SYSMIS.
>
> I'm thinking I would use either the "select if" or "do if" commands to
> identify cases where the value in the second choice variable is identical
> to
> the value in the first choice variable, but I'm not sure what command I
> would use to complete the transformation of the duplicate values
> identified
> in this way into SYSMIS.
>
> Can anyone point me in the right direction?
>
> Thanks very much!
>
>
>
> --
> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: DO IF

Art Kendall
In reply to this post by 88videos
Since you say you are a noobie, here are some ways to avoid shooting your
self in the foot.
(1) always keep it possible to go back and redraft your syntax so that it
does what you evolve as your intention. create a new variable.
(2) Preserve the distinction between user- missing and system missing. You
know why the value for the second choice is to be treated as missing.  It is
NOT because the system is unable to follow your instructions. never put
SYSMIS as the value to be assigned to variable.
(3) Preserve the distinction between logical operators (e.g., EQ, NE)  and
the assignment operator "=".
(4) whenever applicable be sure that valid and missing values are labelled.
(5) integer values are more readable without trailing decimals.
(6) unnecessary EXECUTE commands can slow things down if you have a lot of
data.





-----
Art Kendall
Social Research Consultants
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: DO IF

John F Hall
I agree with Art.  Bruce also forgot to get rid of superfluous decimals.
How about . . ?

compute x = v2 - v1.
formats x (f2.0).
recode x (1 thru hi = 1)(lo thru -1 =2).
var lab x 'v1 same or different to v2'.
val lab x 0 'Same' 1 'Higher' 2 'Lower'.


John F Hall
[Retired academic survey researcher]
IBM-SPSS Academic Author 9900074

Website:          http://surveyresearch.weebly.com/ 
SPSS course:
http://surveyresearch.weebly.com/1-survey-analysis-workshop-spss.html 
Research:
http://surveyresearch.weebly.com/3-subjective-social-indicators-quality-of-l
ife.html


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Art
Kendall
Sent: 01 October 2017 16:14
To: [hidden email]
Subject: Re: DO IF

Since you say you are a noobie, here are some ways to avoid shooting your
self in the foot.
(1) always keep it possible to go back and redraft your syntax so that it
does what you evolve as your intention. create a new variable.
(2) Preserve the distinction between user- missing and system missing. You
know why the value for the second choice is to be treated as missing.  It is
NOT because the system is unable to follow your instructions. never put
SYSMIS as the value to be assigned to variable.
(3) Preserve the distinction between logical operators (e.g., EQ, NE)  and
the assignment operator "=".
(4) whenever applicable be sure that valid and missing values are labelled.
(5) integer values are more readable without trailing decimals.
(6) unnecessary EXECUTE commands can slow things down if you have a lot of
data.





-----
Art Kendall
Social Research Consultants
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command SIGNOFF SPSSX-L For a list of
commands to manage subscriptions, send the command INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: DO IF

Bruce Weaver
Administrator
John, you didn't get around to computing the variable that Will really
wants--i.e., a version of Choice2 that is set to missing if Choice2 is the
same as Choice1.

* AK point #1:  Make a copy of the original Choice2 variable in case it is
needed later.
COMPUTE Choice2Backup = Choice2.
FORMATS Choice2Backup (F5.0).
VARIABLE LABELS Choice2Backup "Copy of original Choice2 variable".

* Choice2 cannot be the same as Choice1.
* If it is, set Choice2 to a user-defined missing value.
IF (Choice2 EQ Choice1) Choice2 = -999.
MISSING VALUES Choice2 (-999).
ADD VALUE LABELS Choice2 -999 "Identical to Choice1, so set to missing
value".



John F Hall wrote

> I agree with Art.  Bruce also forgot to get rid of superfluous decimals.
> How about . . ?
>
> compute x = v2 - v1.
> formats x (f2.0).
> recode x (1 thru hi = 1)(lo thru -1 =2).
> var lab x 'v1 same or different to v2'.
> val lab x 0 'Same' 1 'Higher' 2 'Lower'.
>
>
> John F Hall
> [Retired academic survey researcher]
> IBM-SPSS Academic Author 9900074
>
> Website:          http://surveyresearch.weebly.com/ 
> SPSS course:
> http://surveyresearch.weebly.com/1-survey-analysis-workshop-spss.html 
> Research:
> http://surveyresearch.weebly.com/3-subjective-social-indicators-quality-of-l
> ife.html
>
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:

> SPSSX-L@.UGA

> ] On Behalf Of Art
> Kendall
> Sent: 01 October 2017 16:14
> To:

> SPSSX-L@.UGA

> Subject: Re: DO IF
>
> Since you say you are a noobie, here are some ways to avoid shooting your
> self in the foot.
> (1) always keep it possible to go back and redraft your syntax so that it
> does what you evolve as your intention. create a new variable.
> (2) Preserve the distinction between user- missing and system missing. You
> know why the value for the second choice is to be treated as missing.  It
> is
> NOT because the system is unable to follow your instructions. never put
> SYSMIS as the value to be assigned to variable.
> (3) Preserve the distinction between logical operators (e.g., EQ, NE)  and
> the assignment operator "=".
> (4) whenever applicable be sure that valid and missing values are
> labelled.
> (5) integer values are more readable without trailing decimals.
> (6) unnecessary EXECUTE commands can slow things down if you have a lot of
> data.
>
>
>
>
>
> -----
> Art Kendall
> Social Research Consultants
> --
> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command SIGNOFF SPSSX-L For a list of
> commands to manage subscriptions, send the command INFO REFCARD
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.
Reply | Threaded
Open this post in threaded view
|

Re: DO IF

John F Hall
OK Bruce, but he can always use:
missing values x (0).
At least my code tells Will whether the second choice is higher or lower.
John


John F Hall
[Retired academic survey researcher]
IBM-SPSS Academic Author 9900074

Website:          http://surveyresearch.weebly.com/ 
SPSS course:
http://surveyresearch.weebly.com/1-survey-analysis-workshop-spss.html 
Research:
http://surveyresearch.weebly.com/3-subjective-social-indicators-quality-of-l
ife.html


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Bruce Weaver
Sent: 02 October 2017 17:39
To: [hidden email]
Subject: Re: DO IF

John, you didn't get around to computing the variable that Will really
wants--i.e., a version of Choice2 that is set to missing if Choice2 is the
same as Choice1.

* AK point #1:  Make a copy of the original Choice2 variable in case it is
needed later.
COMPUTE Choice2Backup = Choice2.
FORMATS Choice2Backup (F5.0).
VARIABLE LABELS Choice2Backup "Copy of original Choice2 variable".

* Choice2 cannot be the same as Choice1.
* If it is, set Choice2 to a user-defined missing value.
IF (Choice2 EQ Choice1) Choice2 = -999.
MISSING VALUES Choice2 (-999).
ADD VALUE LABELS Choice2 -999 "Identical to Choice1, so set to missing
value".



John F Hall wrote

> I agree with Art.  Bruce also forgot to get rid of superfluous decimals.
> How about . . ?
>
> compute x = v2 - v1.
> formats x (f2.0).
> recode x (1 thru hi = 1)(lo thru -1 =2).
> var lab x 'v1 same or different to v2'.
> val lab x 0 'Same' 1 'Higher' 2 'Lower'.
>
>
> John F Hall
> [Retired academic survey researcher]
> IBM-SPSS Academic Author 9900074
>
> Website:          http://surveyresearch.weebly.com/ 
> SPSS course:
> http://surveyresearch.weebly.com/1-survey-analysis-workshop-spss.html
> Research:
> http://surveyresearch.weebly.com/3-subjective-social-indicators-qualit
> y-of-l
> ife.html
>
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:

> SPSSX-L@.UGA

> ] On Behalf Of Art
> Kendall
> Sent: 01 October 2017 16:14
> To:

> SPSSX-L@.UGA

> Subject: Re: DO IF
>
> Since you say you are a noobie, here are some ways to avoid shooting
> your self in the foot.
> (1) always keep it possible to go back and redraft your syntax so that
> it does what you evolve as your intention. create a new variable.
> (2) Preserve the distinction between user- missing and system missing.
> You know why the value for the second choice is to be treated as
> missing.  It is NOT because the system is unable to follow your
> instructions. never put SYSMIS as the value to be assigned to
> variable.
> (3) Preserve the distinction between logical operators (e.g., EQ, NE)  
> and the assignment operator "=".
> (4) whenever applicable be sure that valid and missing values are
> labelled.
> (5) integer values are more readable without trailing decimals.
> (6) unnecessary EXECUTE commands can slow things down if you have a
> lot of data.
>
>
>
>
>
> -----
> Art Kendall
> Social Research Consultants
> --
> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (not to SPSSX-L), with no body text except the command. To leave the
> list, send the command SIGNOFF SPSSX-L For a list of commands to
> manage subscriptions, send the command INFO REFCARD
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (not to SPSSX-L), with no body text except the command. To leave the
> list, send the command SIGNOFF SPSSX-L For a list of commands to
> manage subscriptions, send the command INFO REFCARD





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command SIGNOFF SPSSX-L For a list of
commands to manage subscriptions, send the command INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD