Discussion:
Create new variables from others (If Condistional or recode)
(too old to reply)
Betsabé Cohen
2017-10-23 16:12:03 UTC
Permalink
Hi everyone:
I'm a recent user of PSPP and i'm trying to create a new variable from
three other variables using a conditional. In Excel i would use IF and OR
functions but i don't know what should i used in pspp sintaxys:

The idea is to create a new variable as follows:


NEW Variable "Condicion_Actividad"
Existing variables
Cod.1= Var5=1 or Var6=1 or Var7=1
Cod.2= Var8=1
Cod.3= Var8=2

Thanks in advance.

Betsy




<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
Libre
de virus. www.avg.com
<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
John Darrington
2017-10-23 17:00:17 UTC
Permalink
In PSPP, the simplest way to create a new variable, and assign values
to it derived from existing variables is using the COMPUTE command.
For example if you have existing variables v1, v2 and v3, you could
create a new variable as follows:

compute newVar = v1 or v2 or v3.

(don't forget the . at the end)

J'

On Mon, Oct 23, 2017 at 01:12:03PM -0300, Betsab?? Cohen wrote:
Hi everyone:
I'm a recent user of PSPP and i'm trying to create a new variable from
three other variables using a conditional. In Excel i would use IF and OR
functions but i don't know what should i used in pspp sintaxys:

The idea is to create a new variable as follows:


NEW Variable "Condicion_Actividad"
Existing variables
Cod.1= Var5=1 or Var6=1 or Var7=1
Cod.2= Var8=1
Cod.3= Var8=2

Thanks in advance.

Betsy
--
Avoid eavesdropping. Send strong encrypted email.
PGP Public key ID: 1024D/2DE827B3
fingerprint = 8797 A26D 0854 2EAB 0285 A290 8A67 719C 2DE8 27B3
See http://sks-keyservers.net or any PGP keyserver for public key.
Alan Mead
2017-10-23 17:03:20 UTC
Permalink
And if John's explanation is insufficient, please explain what you are
trying to do. A recode statement (if your conditions depend on values of
one variable) or compute statements in IF or DO IF blocks (otherwise)
may be necessary to accomplish what you want.

-Alan
Post by John Darrington
In PSPP, the simplest way to create a new variable, and assign values
to it derived from existing variables is using the COMPUTE command.
For example if you have existing variables v1, v2 and v3, you could
compute newVar = v1 or v2 or v3.
(don't forget the . at the end)
J'
I'm a recent user of PSPP and i'm trying to create a new variable from
three other variables using a conditional. In Excel i would use IF and OR
NEW Variable "Condicion_Actividad"
Existing variables
Cod.1= Var5=1 or Var6=1 or Var7=1
Cod.2= Var8=1
Cod.3= Var8=2
Thanks in advance.
Betsy
_______________________________________________
Pspp-users mailing list
https://lists.gnu.org/mailman/listinfo/pspp-users
--
Alan D. Mead, Ph.D.
President, Talent Algorithms Inc.

science + technology = better workers

http://www.alanmead.org

I've... seen things you people wouldn't believe...
functions on fire in a copy of Orion.
I watched C-Sharp glitter in the dark near a programmable gate.
All those moments will be lost in time, like Ruby... on... Rails... Time for Pi.

--"The Register" user Alister, applying the famous
"Blade Runner" speech to software development
Alan Mead
2017-10-23 20:45:28 UTC
Permalink
Let's assume you have variables X1, x2, x3, etc. and you wish to create
a new variable cond with values like 1, 2, 3, etc. then do one of these:

if( x1 = 1 or x2 = 3) cond = 1.
if( (x2 = 1 and x4=1) or x3 = 1) cond = 2.
etc....
execute.

OR, do this:

do if( x1 = 1 or x2 = 3).
  compute cond = 1.
else if( (x2 = 1 and x4=1) or x3 = 1).
  compute cond = 2.
else.
  compute cond = -1.
end if.
execute.

The main difference is that the second method assures that cond is
assigned something. But unassigned values will be system missing, so
maybe that's better.

If you had a single variable that you wanted to create a new variable
with grouped values, then RECODE would be easier but AFAIK it only works
on values from a single variable.

-Alan
Hi john and Alan 
I’d like to create a new variable where, given certain codes in
certain variables you get other codes in the new variable: if
respondent answer code 1 un variables 5,6 or 7 so in the new variable
it should be code 1, if respondent gets code 1 in variable 8 it should
be code 2 in the new variable but if respondent gets code 2 it should
be code 3 in the new variable.
I wonder sintaxis should be condtional if do, but i dont know...
And if John's explanation is insufficient, please explain what you
are trying to do. A recode statement (if your conditions depend on
values of one variable) or compute statements in IF or DO IF
blocks (otherwise) may be necessary to accomplish what you want.
-Alan
Post by John Darrington
In PSPP, the simplest way to create a new variable, and assign values
to it derived from existing variables is using the COMPUTE command.
For example if you have existing variables v1, v2 and v3, you could
compute newVar = v1 or v2 or v3.
(don't forget the . at the end)
J'
I'm a recent user of PSPP and i'm trying to create a new variable from
three other variables using a conditional. In Excel i would use IF and OR
NEW Variable "Condicion_Actividad"
Existing variables
Cod.1= Var5=1 or Var6=1 or Var7=1
Cod.2= Var8=1
Cod.3= Var8=2
Thanks in advance.
Betsy
_______________________________________________
Pspp-users mailing list
https://lists.gnu.org/mailman/listinfo/pspp-users
--
Alan D. Mead, Ph.D.
President, Talent Algorithms Inc.
science + technology = better workers
http://www.alanmead.org
I've... seen things you people wouldn't believe...
functions on fire in a copy of Orion.
I watched C-Sharp glitter in the dark near a programmable gate.
All those moments will be lost in time, like Ruby... on... Rails... Time for Pi.
--"The Register" user Alister, applying the famous
"Blade Runner" speech to software development
--
*
*
*LIC. BETSABE LAILA COHEN*
CEL: +54911 5701 3993
--
Alan D. Mead, Ph.D.
President, Talent Algorithms Inc.

science + technology = better workers

http://www.alanmead.org

I've... seen things you people wouldn't believe...
functions on fire in a copy of Orion.
I watched C-Sharp glitter in the dark near a programmable gate.
All those moments will be lost in time, like Ruby... on... Rails... Time for Pi.

--"The Register" user Alister, applying the famous
"Blade Runner" speech to software development
Alan Mead
2017-10-27 16:52:15 UTC
Permalink
You have the syntax wrong. I imagined variable V1.  I have no idea is
this accomplishes what you want, it just corrects the syntax to
illustrate how you have the syntax wrong. The spacing before the
RECODE/COMPUTE statements is just to make it easier to read.

DO IF(P5=2 or P6=2 or P7=2).
   RECODE V1 (2=1) INTO Var0001.
ELSE IF (P8=1).
  RECODE P8 (1=2) into Var0001.
ELSE.
   COMPUTE Var0001=3
EXECUTE.

Also, I don't think you need to use RECODE:

DO IF(P5=2 or P6=2 or P7=2).
   COMPUTE Var0001 = 1.
ELSE IF (P8=1).
   COMPUTE Var0001 = 2.
ELSE.
   COMPUTE Var0001 = 3
EXECUTE.
Hi Alan: 
I wrote it like this and still result error: 
DO IF(P5=2 or P6=2 or P7=2) RECODE (2=1) INTO Var0001
ELSE IF (P8=1) 
RECODE P8 
(1=2) 
ELSE COMPUTE 3
EXECUTE.
*
*
*LIC. BETSABE LAILA COHEN*
CEL: +54911 5701 3993
Let's assume you have variables X1, x2, x3, etc. and you wish to
create a new variable cond with values like 1, 2, 3, etc. then do
if( x1 = 1 or x2 = 3) cond = 1.
if( (x2 = 1 and x4=1) or x3 = 1) cond = 2.
etc....
execute.
do if( x1 = 1 or x2 = 3).
  compute cond = 1.
else if( (x2 = 1 and x4=1) or x3 = 1).
  compute cond = 2.
else.
  compute cond = -1.
end if.
execute.
The main difference is that the second method assures that cond is
assigned something. But unassigned values will be system missing,
so maybe that's better.
If you had a single variable that you wanted to create a new
variable with grouped values, then RECODE would be easier but
AFAIK it only works on values from a single variable.
-Alan
Hi john and Alan 
I’d like to create a new variable where, given certain codes in
certain variables you get other codes in the new variable: if
respondent answer code 1 un variables 5,6 or 7 so in the new
variable it should be code 1, if respondent gets code 1 in
variable 8 it should be code 2 in the new variable but if
respondent gets code 2 it should be code 3 in the new variable.
I wonder sintaxis should be condtional if do, but i dont know...
El El lun, 23 oct. 2017 a las 14:03, Alan Mead
And if John's explanation is insufficient, please explain
what you are trying to do. A recode statement (if your
conditions depend on values of one variable) or compute
statements in IF or DO IF blocks (otherwise) may be necessary
to accomplish what you want.
-Alan
Post by John Darrington
In PSPP, the simplest way to create a new variable, and assign values
to it derived from existing variables is using the COMPUTE command.
For example if you have existing variables v1, v2 and v3, you could
compute newVar = v1 or v2 or v3.
(don't forget the . at the end)
J'
I'm a recent user of PSPP and i'm trying to create a new variable from
three other variables using a conditional. In Excel i would use IF and OR
NEW Variable "Condicion_Actividad"
Existing variables
Cod.1= Var5=1 or Var6=1 or Var7=1
Cod.2= Var8=1
Cod.3= Var8=2
Thanks in advance.
Betsy
_______________________________________________
Pspp-users mailing list
https://lists.gnu.org/mailman/listinfo/pspp-users
<https://lists.gnu.org/mailman/listinfo/pspp-users>
--
Alan D. Mead, Ph.D.
President, Talent Algorithms Inc.
science + technology = better workers
http://www.alanmead.org
I've... seen things you people wouldn't believe...
functions on fire in a copy of Orion.
I watched C-Sharp glitter in the dark near a programmable gate.
All those moments will be lost in time, like Ruby... on... Rails... Time for Pi.
--"The Register" user Alister, applying the famous
"Blade Runner" speech to software development
--
*
*
*LIC. BETSABE LAILA COHEN*
CEL: +54911 5701 3993
--
Alan D. Mead, Ph.D.
President, Talent Algorithms Inc.
science + technology = better workers
http://www.alanmead.org
I've... seen things you people wouldn't believe...
functions on fire in a copy of Orion.
I watched C-Sharp glitter in the dark near a programmable gate.
All those moments will be lost in time, like Ruby... on... Rails... Time for Pi.
--"The Register" user Alister, applying the famous
"Blade Runner" speech to software development
--
Alan D. Mead, Ph.D.
President, Talent Algorithms Inc.

science + technology = better workers

http://www.alanmead.org

I've... seen things you people wouldn't believe...
functions on fire in a copy of Orion.
I watched C-Sharp glitter in the dark near a programmable gate.
All those moments will be lost in time, like Ruby... on... Rails... Time for Pi.

--"The Register" user Alister, applying the famous
"Blade Runner" speech to software development
Alan Mead
2017-10-27 17:00:15 UTC
Permalink
Sorry, I forgot to add "END IF." Here's where it would go:

DO IF(P5=2 or P6=2 or P7=2).
   COMPUTE Var0001 = 1.
ELSE IF (P8=1).
   COMPUTE Var0001 = 2.
ELSE.
   COMPUTE Var0001 = 3
END IF.
EXECUTE.
Post by Alan Mead
You have the syntax wrong. I imagined variable V1.  I have no idea is
this accomplishes what you want, it just corrects the syntax to
illustrate how you have the syntax wrong. The spacing before the
RECODE/COMPUTE statements is just to make it easier to read.
DO IF(P5=2 or P6=2 or P7=2).
   RECODE V1 (2=1) INTO Var0001.
ELSE IF (P8=1).
  RECODE P8 (1=2) into Var0001.
ELSE.
   COMPUTE Var0001=3
EXECUTE.
DO IF(P5=2 or P6=2 or P7=2).
   COMPUTE Var0001 = 1.
ELSE IF (P8=1).
   COMPUTE Var0001 = 2.
ELSE.
   COMPUTE Var0001 = 3
EXECUTE.
Hi Alan: 
I wrote it like this and still result error: 
DO IF(P5=2 or P6=2 or P7=2) RECODE (2=1) INTO Var0001
ELSE IF (P8=1) 
RECODE P8 
(1=2) 
ELSE COMPUTE 3
EXECUTE.
*
*
*LIC. BETSABE LAILA COHEN*
CEL: +54911 5701 3993
Let's assume you have variables X1, x2, x3, etc. and you wish to
create a new variable cond with values like 1, 2, 3, etc. then do
if( x1 = 1 or x2 = 3) cond = 1.
if( (x2 = 1 and x4=1) or x3 = 1) cond = 2.
etc....
execute.
do if( x1 = 1 or x2 = 3).
  compute cond = 1.
else if( (x2 = 1 and x4=1) or x3 = 1).
  compute cond = 2.
else.
  compute cond = -1.
end if.
execute.
The main difference is that the second method assures that cond
is assigned something. But unassigned values will be system
missing, so maybe that's better.
If you had a single variable that you wanted to create a new
variable with grouped values, then RECODE would be easier but
AFAIK it only works on values from a single variable.
-Alan
Hi john and Alan 
I’d like to create a new variable where, given certain codes in
certain variables you get other codes in the new variable: if
respondent answer code 1 un variables 5,6 or 7 so in the new
variable it should be code 1, if respondent gets code 1 in
variable 8 it should be code 2 in the new variable but if
respondent gets code 2 it should be code 3 in the new variable.
I wonder sintaxis should be condtional if do, but i dont know...
El El lun, 23 oct. 2017 a las 14:03, Alan Mead
And if John's explanation is insufficient, please explain
what you are trying to do. A recode statement (if your
conditions depend on values of one variable) or compute
statements in IF or DO IF blocks (otherwise) may be
necessary to accomplish what you want.
-Alan
Post by John Darrington
In PSPP, the simplest way to create a new variable, and assign values
to it derived from existing variables is using the COMPUTE command.
For example if you have existing variables v1, v2 and v3, you could
compute newVar = v1 or v2 or v3.
(don't forget the . at the end)
J'
I'm a recent user of PSPP and i'm trying to create a new variable from
three other variables using a conditional. In Excel i would use IF and OR
NEW Variable "Condicion_Actividad"
Existing variables
Cod.1= Var5=1 or Var6=1 or Var7=1
Cod.2= Var8=1
Cod.3= Var8=2
Thanks in advance.
Betsy
_______________________________________________
Pspp-users mailing list
https://lists.gnu.org/mailman/listinfo/pspp-users
<https://lists.gnu.org/mailman/listinfo/pspp-users>
--
Alan D. Mead, Ph.D.
President, Talent Algorithms Inc.
science + technology = better workers
http://www.alanmead.org
I've... seen things you people wouldn't believe...
functions on fire in a copy of Orion.
I watched C-Sharp glitter in the dark near a programmable gate.
All those moments will be lost in time, like Ruby... on... Rails... Time for Pi.
--"The Register" user Alister, applying the famous
"Blade Runner" speech to software development
--
*
*
*LIC. BETSABE LAILA COHEN*
CEL: +54911 5701 3993
--
Alan D. Mead, Ph.D.
President, Talent Algorithms Inc.
science + technology = better workers
http://www.alanmead.org
I've... seen things you people wouldn't believe...
functions on fire in a copy of Orion.
I watched C-Sharp glitter in the dark near a programmable gate.
All those moments will be lost in time, like Ruby... on... Rails... Time for Pi.
--"The Register" user Alister, applying the famous
"Blade Runner" speech to software development
--
Alan D. Mead, Ph.D.
President, Talent Algorithms Inc.
science + technology = better workers
http://www.alanmead.org
I've... seen things you people wouldn't believe...
functions on fire in a copy of Orion.
I watched C-Sharp glitter in the dark near a programmable gate.
All those moments will be lost in time, like Ruby... on... Rails... Time for Pi.
--"The Register" user Alister, applying the famous
"Blade Runner" speech to software development
_______________________________________________
Pspp-users mailing list
https://lists.gnu.org/mailman/listinfo/pspp-users
--
Alan D. Mead, Ph.D.
President, Talent Algorithms Inc.

science + technology = better workers

http://www.alanmead.org

I've... seen things you people wouldn't believe...
functions on fire in a copy of Orion.
I watched C-Sharp glitter in the dark near a programmable gate.
All those moments will be lost in time, like Ruby... on... Rails... Time for Pi.

--"The Register" user Alister, applying the famous
"Blade Runner" speech to software development
Alan Mead
2017-10-27 17:41:25 UTC
Permalink
It's hard to test syntax without the data so it's better to post short
syntax files and small datafiles.

There was a typo (no period after the third compute statement) but even
after I fix that it doesn't work. Var0001 is missing when the first DO
IF doesn't fire. I am also mystified as to why; possibly DO IF is
sensitive to missing values (my example had missing values, not sure if
yous does). I thought it might be a PSPP bug, but the same thing happens
in SPSS.

But the second block works for me in both PSPP and SPSS.

-Alan
Thank you for your help but this sintaxys is not working
Maybe I'm not being clear: I need to create a new variable (Var0001)
starting from a series of existings variables (P5,P6,P7 andP8)  with
When P5,P6 or P7 is equal to code 2  Var0001 should compute code 1
When P8 is equal to code 1 Var0001 should compute code 2
When P8 is equal to code 2 Var0001 should compute code 3
*
*
*LIC. BETSABE LAILA COHEN*
CEL: +54911 5701 3993
DO IF(P5=2 or P6=2 or P7=2).
   COMPUTE Var0001 = 1.
ELSE IF (P8=1).
   COMPUTE Var0001 = 2.
ELSE.
   COMPUTE Var0001 = 3
END IF.
EXECUTE.
Post by Alan Mead
You have the syntax wrong. I imagined variable V1.  I have no
idea is this accomplishes what you want, it just corrects the
syntax to illustrate how you have the syntax wrong. The spacing
before the RECODE/COMPUTE statements is just to make it easier to
read.
DO IF(P5=2 or P6=2 or P7=2).
   RECODE V1 (2=1) INTO Var0001.
ELSE IF (P8=1).
  RECODE P8 (1=2) into Var0001.
ELSE.
   COMPUTE Var0001=3
EXECUTE.
DO IF(P5=2 or P6=2 or P7=2).
   COMPUTE Var0001 = 1.
ELSE IF (P8=1).
   COMPUTE Var0001 = 2.
ELSE.
   COMPUTE Var0001 = 3
EXECUTE.
Hi Alan: 
I wrote it like this and still result error: 
DO IF(P5=2 or P6=2 or P7=2) RECODE (2=1) INTO Var0001
ELSE IF (P8=1) 
RECODE P8 
(1=2) 
ELSE COMPUTE 3
EXECUTE.
*
*
*LIC. BETSABE LAILA COHEN*
CEL: +54911 5701 3993
Let's assume you have variables X1, x2, x3, etc. and you
wish to create a new variable cond with values like 1, 2, 3,
if( x1 = 1 or x2 = 3) cond = 1.
if( (x2 = 1 and x4=1) or x3 = 1) cond = 2.
etc....
execute.
do if( x1 = 1 or x2 = 3).
  compute cond = 1.
else if( (x2 = 1 and x4=1) or x3 = 1).
  compute cond = 2.
else.
  compute cond = -1.
end if.
execute.
The main difference is that the second method assures that
cond is assigned something. But unassigned values will be
system missing, so maybe that's better.
If you had a single variable that you wanted to create a new
variable with grouped values, then RECODE would be easier
but AFAIK it only works on values from a single variable.
-Alan
Hi john and Alan 
I’d like to create a new variable where, given certain
codes in certain variables you get other codes in the new
variable: if respondent answer code 1 un variables 5,6 or 7
so in the new variable it should be code 1, if respondent
gets code 1 in variable 8 it should be code 2 in the new
variable but if respondent gets code 2 it should be code 3
in the new variable.
I wonder sintaxis should be condtional if do, but i dont know...
El El lun, 23 oct. 2017 a las 14:03, Alan Mead
And if John's explanation is insufficient, please
explain what you are trying to do. A recode statement
(if your conditions depend on values of one variable)
or compute statements in IF or DO IF blocks (otherwise)
may be necessary to accomplish what you want.
-Alan
Post by John Darrington
In PSPP, the simplest way to create a new variable, and assign values
to it derived from existing variables is using the COMPUTE command.
For example if you have existing variables v1, v2 and v3, you could
compute newVar = v1 or v2 or v3.
(don't forget the . at the end)
J'
I'm a recent user of PSPP and i'm trying to create a new variable from
three other variables using a conditional. In Excel i would use IF and OR
NEW Variable "Condicion_Actividad"
Existing variables
Cod.1= Var5=1 or Var6=1 or Var7=1
Cod.2= Var8=1
Cod.3= Var8=2
Thanks in advance.
Betsy
_______________________________________________
Pspp-users mailing list
https://lists.gnu.org/mailman/listinfo/pspp-users
<https://lists.gnu.org/mailman/listinfo/pspp-users>
--
Alan D. Mead, Ph.D.
President, Talent Algorithms Inc.
science + technology = better workers
http://www.alanmead.org
I've... seen things you people wouldn't believe...
functions on fire in a copy of Orion.
I watched C-Sharp glitter in the dark near a programmable gate.
All those moments will be lost in time, like Ruby... on... Rails... Time for Pi.
--"The Register" user Alister, applying the famous
"Blade Runner" speech to software development
--
*
*
*LIC. BETSABE LAILA COHEN*
CEL: +54911 5701 3993
--
Alan D. Mead, Ph.D.
President, Talent Algorithms Inc.
science + technology = better workers
http://www.alanmead.org
I've... seen things you people wouldn't believe...
functions on fire in a copy of Orion.
I watched C-Sharp glitter in the dark near a programmable gate.
All those moments will be lost in time, like Ruby... on... Rails... Time for Pi.
--"The Register" user Alister, applying the famous
"Blade Runner" speech to software development
--
Alan D. Mead, Ph.D.
President, Talent Algorithms Inc.
science + technology = better workers
http://www.alanmead.org
I've... seen things you people wouldn't believe...
functions on fire in a copy of Orion.
I watched C-Sharp glitter in the dark near a programmable gate.
All those moments will be lost in time, like Ruby... on... Rails... Time for Pi.
--"The Register" user Alister, applying the famous
"Blade Runner" speech to software development
_______________________________________________
Pspp-users mailing list
https://lists.gnu.org/mailman/listinfo/pspp-users
<https://lists.gnu.org/mailman/listinfo/pspp-users>
--
Alan D. Mead, Ph.D.
President, Talent Algorithms Inc.
science + technology = better workers
http://www.alanmead.org
I've... seen things you people wouldn't believe...
functions on fire in a copy of Orion.
I watched C-Sharp glitter in the dark near a programmable gate.
All those moments will be lost in time, like Ruby... on... Rails... Time for Pi.
--"The Register" user Alister, applying the famous
"Blade Runner" speech to software development
--
Alan D. Mead, Ph.D.
President, Talent Algorithms Inc.

science + technology = better workers

http://www.alanmead.org

I've... seen things you people wouldn't believe...
functions on fire in a copy of Orion.
I watched C-Sharp glitter in the dark near a programmable gate.
All those moments will be lost in time, like Ruby... on... Rails... Time for Pi.

--"The Register" user Alister, applying the famous
"Blade Runner" speech to software development
Loading...