pspp-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Create new variables from others (If Condistional or recode)


From: Alan Mead
Subject: Re: Create new variables from others (If Condistional or recode)
Date: Fri, 27 Oct 2017 12:41:25 -0500
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0

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


On 10/27/2017 12:14 PM, Betsabé Cohen wrote:
Hi 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 this conditions:
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



2017-10-27 14:00 GMT-03:00 Alan Mead <address@hidden>:
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.


On 10/27/2017 11:52 AM, Alan Mead wrote:
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.

On 10/27/2017 11:45 AM, Betsabé Cohen wrote:
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



2017-10-23 17:45 GMT-03:00 Alan Mead <address@hidden>:
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




On 10/23/2017 3:37 PM, Betsabé Cohen wrote:
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 <address@hidden> escribió:
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


On 10/23/2017 12:00 PM, John Darrington wrote:
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
     
     


_______________________________________________
Pspp-users mailing list
address@hidden
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
address@hidden
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

Attachment: example.sav
Description: application/spss-sav

Attachment: example.sps
Description: application/spss-sps


reply via email to

[Prev in Thread] Current Thread [Next in Thread]