Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Transform variable

4 views
Skip to first unread message

gregius

unread,
Aug 5, 2005, 8:48:23 AM8/5/05
to
Hi,

I'm a new user of SPSS 12 and i have a specific problem.
I've different nominal variables

Town var1 var2
BXl A B
Paris B D
...

i would like to have a new table where all the different forms of the
variables become a binary variable : like this

Town Var1A Var1B Var2B Var2D
BXL 1 0 1 0
Paris 0 1 0 1

I've try a script binarisation.sbs
(http://www.spss.com/fr/Downloads/Binarisation.SBS)
but i can't use it, it always says there's an error in the script...

Anybody can help me?

Message has been deleted

Bruce Weaver

unread,
Aug 5, 2005, 10:25:40 AM8/5/05
to


compute var1a = (var1 = 'A').
compute var1b = (var1 = 'B').
compute var2b = (var2 = 'B').
compute var2d = (var2 = 'D').
format var1a to var2d (f1.0).
list.

--
Bruce Weaver
bwe...@lakeheadu.ca
www.angelfire.com/wv/bwhomedir

gregius

unread,
Aug 6, 2005, 3:09:59 AM8/6/05
to
I have to put it in a script i suppose...
I did it but there is an error : compute <here>var1a = (var1 = 'A').
(0) invalid instruction.

Heeeelp.

You have also to know that i have in fact 50 variables with differents
answers who have all to become binary variables...

Thanks

Greg

Bruce Weaver

unread,
Aug 6, 2005, 10:46:06 AM8/6/05
to
gregius wrote:
> I have to put it in a script i suppose...
> I did it but there is an error : compute <here>var1a = (var1 = 'A').
> (0) invalid instruction.

I don't undestand why you have "<here>" in that compute statement. What
is it supposed to signify?

>
> Heeeelp.
>
> You have also to know that i have in fact 50 variables with differents
> answers who have all to become binary variables...
>
> Thanks
>
> Greg


IN that case, I think you'll want either a DO-REPEAT loop or a macro. I
won't try to write any code for that today, because I don't have SPSS at
home to test it.

gregius

unread,
Aug 6, 2005, 12:18:34 PM8/6/05
to
ok, thanks to help, i've had a look on your site... very usefull...
i'll use the tutorials i think.
for the script... i don't understand why there is a "<here> too...

I would be great if there is a script that can detect all the different
form of the variable and create a new binary one...
Like i said before the script binarisation should be able to do it...
but it doesn't... Even if i introduced all the values of the variable
in spss...

I can wait 'till monday, no problem... i'll look for the do-repeat
function

Thanks

Greg

lobin

unread,
Aug 7, 2005, 12:11:33 PM8/7/05
to

Hej!

if you have string variables try this macro:

define !BIN (!positional= !charend('|')
/LETT =!default (A) !charend ('|')
/nazwa=!default(new_) !charend('|') ).
!let !lista=!lett.
!do !j !in (!1).
!DO !I !IN (!lista).
!let !lette=!head(!lista).
!let !lista=!tail(!lista).
if (!j=!quote(!lette)) !concat(!j,'_',!lette)=1.
recode !concat(!j,'_',!lette) (sysmis=0).
!DOEND.
!let !lista=!lett.
!doend.
!enddefine.


!bin var1 var2 |lett =A B D.

if you have more letters then tree insert all of them into parametr
lett, fg. lett= A B C D E F
If you have more then two variables paste all of them after name of
macro fg. !bin var1 var2 var3 .... var50

Is it this what you want?

Lobin

gregius napisał(a):


> Hi,
>
> I'm a new user of SPSS 12 and i have a specific problem.
> I've different nominal variables
>
> Town var1 var2
> BXl A B
> Paris B D

> ....

Message has been deleted

gregius

unread,
Aug 8, 2005, 3:21:31 AM8/8/05
to
Hey, Bruce,
I've found what was the problem with your first syntax : i put it in a
script and not in a syntax...
that is why he gave this weard message.
but if you can resolve the mystery of the binarisation script... it
could maybe help me...
If not, i'll do your solution.

Many thanks
Greg

Message has been deleted

lobin

unread,
Aug 8, 2005, 5:08:18 AM8/8/05
to
String it is a format of variables in spss.
If you have that format use my macro (in syntax) .
If you have a numeric variables with labels I can write other varsion of
this macro.
It produce exactly what you need, new binary variables (var1_a, var1_b
var1_d Var2_a var2_b var2_d).
Is it that?

lobin

gregius napisał(a):
> what are string variables?
> My variables are like this : profession (doctor, electrician,
> student...)
>

0 new messages