Quantcast
Channel: Transform string variable into 0-1 columns - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Transform string variable into 0-1 columns

$
0
0

As a very begginer in SPSS I would ask you for help with some transformation from table A into table B. I have to recode values of "brand" variable into columns and make 0-1 variables.

#table A#
nr  brand
1   GREEN CARE PROFESSIONAL
1   GREEN CARE PROFESSIONAL
1   GREEN CARE PROFESSIONAL
2   HENKEL
3   HENKEL
3   HENKEL
3   HENKEL
3   VIZIR
4   BIEDRONKA
4   BOBINI
4   BOBINI
4   BOBINI
4   BOBINI
4   BOBINI
4   HENKEL
5   VIZIR
6   HENKEL

#table B#
nr GREEN HENKEL VIZIR BIEDR BOBINI
1   1   0   0   0   0
1   1   0   0   0   0
1   1   1   0   0   0
2   0   1   0   0   0
3   0   1   0   0   0
3   0   1   0   0   0
3   0   1   0   0   0
3   0   0   1   0   0
4   0   0   0   1   0
4   0   0   0   0   1
4   0   0   0   0   1
4   0   0   0   0   1
4   0   0   0   0   1
4   0   0   0   0   1
4   0   1   0   0   0
5   0   0   1   0   0
6   0   1   0   0   0

I can do it in this particular case in this simple way:

compute HENKEL=0.
...
do if BRAND='GREEN_CARE' .
compute GREEN_CARE=1.
else if ....

but the loop has to be usable with another variable and different number of values ect. I was trying to make it all day and gave up.

Do you have any idea to make it in a easy way? Thanks!


Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>