recodes and scratch variables

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

recodes and scratch variables

Frans Marcelissen-3
Hi,
I use a scratch variable in a recode. Then something strange happens. I will show that using both a scratch variable and a normal variable. I would expect that b and d have the same values. But b recieves a value when it should not have one. Everything works fine when there is an else clause, but I still do not understand what is happening.
I have spss 20.
Thanks
Frans
--------------------------

dataset close all.

data list free/a.

begin data

1  2  1  2  1  2  3  4  5 6 1 2
end data.
recode a(1=10)(2=20) into #c.
compute b=#c.
recode a(1=10)(2=20)  into  d.
EXECUTE.
list.
       a        b        d
    1,00    10,00    10,00
    2,00    20,00    20,00
    1,00    10,00    10,00
    2,00    20,00    20,00
    1,00    10,00    10,00
    2,00    20,00    20,00
    3,00    20,00      .
    4,00    20,00      .
    5,00    20,00      .
    6,00    20,00      .
    1,00    10,00    10,00
    2,00    20,00    20,00

Reply | Threaded
Open this post in threaded view
|

Re: recodes and scratch variables

Gerard van Meurs-2

Hi Frans,

 

I think I understand what’s happening. Scratch variables in SPSS are not reinitialized when reading new cases.  So, at the 7th case, the value of #c is still 20, carrying over from the 6th cases, where it was set to 20. In fact, it remains 20, until it is reset by a different value of A.

 

Kind regards,

 

Gerard van Meurs

Evidens onderzoekdiensten BV

Van: SPSSX(r) Discussion [mailto:[hidden email]] Namens Frans Marcelissen
Verzonden: dinsdag 13 december 2011 11:34
Aan: [hidden email]
Onderwerp: recodes and scratch variables

 

Hi,
I use a scratch variable in a recode. Then something strange happens. I will show that using both a scratch variable and a normal variable. I would expect that b and d have the same values. But b recieves a value when it should not have one. Everything works fine when there is an else clause, but I still do not understand what is happening.
I have spss 20.
Thanks
Frans
--------------------------

dataset close all.

data list free/a.

begin data

1  2  1  2  1  2  3  4  5 6 1 2
end data.
recode a(1=10)(2=20) into #c.
compute b=#c.
recode a(1=10)(2=20)  into  d.
EXECUTE.
list.
       a        b        d
    1,00    10,00    10,00
    2,00    20,00    20,00
    1,00    10,00    10,00
    2,00    20,00    20,00
    1,00    10,00    10,00
    2,00    20,00    20,00
    3,00    20,00      .
    4,00    20,00      .
    5,00    20,00      .
    6,00    20,00      .
    1,00    10,00    10,00
    2,00    20,00    20,00

Reply | Threaded
Open this post in threaded view
|

Re: recodes and scratch variables

David Marso
Administrator
"Scratch variables in SPSS are not reinitialized when reading new cases.  "
Precisely!
--
Why is is prudent to *ALWAYS* include a CYA clause in recodes:
OTOH:  In the posted example, one gains absolutely *NOTHING* by use of a scratch variable (except for an open invitation to a programming bug).
--
data list free/a.
begin data
1  2  1  2  1  2  3  4  5 6 1 2
end data.
recode a(1=10)(2=20)(ELSE=SYSMIS) into #c.
compute b=#c.
recode a(1=10)(2=20)(ELSE=SYSMIS) into  d.
list.
Gerard van Meurs wrote
Hi Frans,

 

I think I understand what's happening. Scratch variables in SPSS are not
reinitialized when reading new cases.  So, at the 7th case, the value of
#c is still 20, carrying over from the 6th cases, where it was set to
20. In fact, it remains 20, until it is reset by a different value of A.

 

Kind regards,

 

Gerard van Meurs

Evidens onderzoekdiensten BV

Van: SPSSX(r) Discussion [mailto:[hidden email]] Namens Frans
Marcelissen
Verzonden: dinsdag 13 december 2011 11:34
Aan: [hidden email]
Onderwerp: recodes and scratch variables

 

Hi,
I use a scratch variable in a recode. Then something strange happens. I
will show that using both a scratch variable and a normal variable. I
would expect that b and d have the same values. But b recieves a value
when it should not have one. Everything works fine when there is an else
clause, but I still do not understand what is happening.
I have spss 20.
Thanks
Frans
--------------------------

dataset close all.

data list free/a.

begin data

1  2  1  2  1  2  3  4  5 6 1 2
end data.
recode a(1=10)(2=20) into #c.
compute b=#c.
recode a(1=10)(2=20)  into  d.
EXECUTE.
list.
       a        b        d
    1,00    10,00    10,00
    2,00    20,00    20,00
    1,00    10,00    10,00
    2,00    20,00    20,00
    1,00    10,00    10,00
    2,00    20,00    20,00
    3,00    20,00      .
    4,00    20,00      .
    5,00    20,00      .
    6,00    20,00      .
    1,00    10,00    10,00
    2,00    20,00    20,00
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"