Computing new variable

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

Computing new variable

Larry-98
I am using SPSS version 16 and I'm trying to create a new variable based on
the answers to other variables.  For example, lets say I have 3 variables
called x1, x2, and x3, and I want to create another variable called "new."
I want something like:

If x1 - "y" and x2 = "n" and x3 = "n" then new = 1
If x1 - "y" and x2 = "y" and x3 = "n" then new = 2
etc.

When I try to do this with the compute command I can only put in the fist
statement.  I can't seem to put in the others.  Can any one tell me how this
is done?  If it can't be done from the menu, can it be done using a syntax
file?  Thanks in advance for any guidance you can give me.

=====================
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: Computing new variable

Hector Maletta
Larry,
With the menu you can establish one condition at a time. With syntax you can
issue a number of conditional statements of the kind you mention, then run
all of them.

IF (such and such)new=1.
IF (such other)new=2.
.......
FREQUENCIES new.
When you run a command that requires reading the data, such as FREQUENCIES
(which is only an example), the pending transformations are automatically
executed. You can also execute the transformations without running any
procedure, by simply clicking on the "watch" icon or issuing the EXECUTE
command.
If the various conditions defining the values of your new variables respond
to any general rule or function, perhaps you may use some kind of
abbreviated syntax, perhaps a loop or a formula, instead of a different IF
command for each value of the new variable. However, this is not always
possible. If the combinations of conditions for each value are arbitrary,
you will have to specify them separately.

Hector

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Larry
Sent: 04 December 2008 16:40
To: [hidden email]
Subject: Computing new variable

I am using SPSS version 16 and I'm trying to create a new variable based on
the answers to other variables.  For example, lets say I have 3 variables
called x1, x2, and x3, and I want to create another variable called "new."
I want something like:

If x1 - "y" and x2 = "n" and x3 = "n" then new = 1
If x1 - "y" and x2 = "y" and x3 = "n" then new = 2
etc.

When I try to do this with the compute command I can only put in the fist
statement.  I can't seem to put in the others.  Can any one tell me how this
is done?  If it can't be done from the menu, can it be done using a syntax
file?  Thanks in advance for any guidance you can give me.

=====================
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: Computing new variable

Art Kendall
In reply to this post by Larry-98
SPSS does not use a " then" between the condition and the instruction ry
something like this untested syntax.

If x1 eq "n" and x2 eq "n" and x3 eq "n"  new = 1.
If x1 eq "n" and x2 eq "n" and x3 eq "y"  new = 2.
If x1 eq "n" and x2 eq "y" and x3 eq "n"  new = 3.
If x1 eq "n" and x2 eq "y" and x3 eq "y"  new = 4.
If x1 eq "y" and x2 eq "n" and x3 eq "n"  new = 5.
If x1 eq "y" and x2 eq "n" and x3 eq "y"  new = 6.
If x1 eq "y" and x2 eq "y" and x3 eq "n"  new = 7.
If x1 eq "y" and x2 eq "y" and x3 eq "y"  new = 8.

if you just want to know how many yeses
count new = x1 to x3 ("y", "Y").


Art Kendall
Social Research Consultants


Larry wrote:

> I am using SPSS version 16 and I'm trying to create a new variable based on
> the answers to other variables.  For example, lets say I have 3 variables
> called x1, x2, and x3, and I want to create another variable called "new."
> I want something like:
>
> If x1 - "y" and x2 = "n" and x3 = "n" then new = 1
> If x1 - "y" and x2 = "y" and x3 = "n" then new = 2
> etc.
>
> When I try to do this with the compute command I can only put in the fist
> statement.  I can't seem to put in the others.  Can any one tell me how this
> is done?  If it can't be done from the menu, can it be done using a syntax
> file?  Thanks in advance for any guidance you can give me.
>
> =====================
> 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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Computing new variable

Nancy Darling-2
In reply to this post by Hector Maletta
You can have the best of both worlds if you use the menus to do the
first statement, paste it, then copy it repeatedly and modify it in
syntax.  Below, the first was done in the menu and the second is done in
syntax.

IF  (dating3=1 and bviothb=1 and bvioactb=1) new=3.
IF  (dating3=1 and bviothb=2 and bvioactb=1) new=4.
etc.

Hector Maletta wrote:

> Larry,
> With the menu you can establish one condition at a time. With syntax you can
> issue a number of conditional statements of the kind you mention, then run
> all of them.
>
> IF (such and such)new=1.
> IF (such other)new=2.
> .......
> FREQUENCIES new.
> When you run a command that requires reading the data, such as FREQUENCIES
> (which is only an example), the pending transformations are automatically
> executed. You can also execute the transformations without running any
> procedure, by simply clicking on the "watch" icon or issuing the EXECUTE
> command.
> If the various conditions defining the values of your new variables respond
> to any general rule or function, perhaps you may use some kind of
> abbreviated syntax, perhaps a loop or a formula, instead of a different IF
> command for each value of the new variable. However, this is not always
> possible. If the combinations of conditions for each value are arbitrary,
> you will have to specify them separately.
>
> Hector
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
> Larry
> Sent: 04 December 2008 16:40
> To: [hidden email]
> Subject: Computing new variable
>
> I am using SPSS version 16 and I'm trying to create a new variable based on
> the answers to other variables.  For example, lets say I have 3 variables
> called x1, x2, and x3, and I want to create another variable called "new."
> I want something like:
>
> If x1 - "y" and x2 = "n" and x3 = "n" then new = 1
> If x1 - "y" and x2 = "y" and x3 = "n" then new = 2
> etc.
>
> When I try to do this with the compute command I can only put in the fist
> statement.  I can't seem to put in the others.  Can any one tell me how this
> is done?  If it can't be done from the menu, can it be done using a syntax
> file?  Thanks in advance for any guidance you can give me.
>
> =====================
> 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
>

=====================
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