Create Primary variable from 2 sets of variables

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

Create Primary variable from 2 sets of variables

Mike Pritchard
I'm not sure I'm describing this well, so please forgive any vagueness.

I have one set of variables (S1_1 to S1_8) that cover ownership of
particular devices.  This set is either 1 for owned or 0 for not owned. Then
a second set of variables (S2R1 to S2R_8) that cover usage, with each
variable having a value of 0 to 5, with higher values indicating more usage.

I want to create a variable for the primary device - the one with the most
usage - 'Primary'.  The value would a number (1 to 8) corresponding with
S1_1 to S1_8.

I can't figure out the syntax for this.  I'd be having trouble in any case,
but the problem is more complicated by the fact that the usage responses can
be duplicated.  When there are multiple devices that could each be primary,
I'd like to assign a random device to Primary.

I can conceive of how to do it with Excel (although I haven't yet tried to
create it) but I'm sure it could be done with SPSS if I knew how.

Any suggestions would be most appreciated.

Thanks
Mike

_________________________________________________________________________
Mike Pritchard | [hidden email] | 5 Circles Research | 425-444-3410 (c)
| 425-968-3883 (o)
Research to help companies build products that people buy

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Create Primary variable from 2 sets of variables

Ruben Geert van den Berg
Dear Mike,

I don't see why you'd need the first 8 variables here so I left them out in the example below. In case of ties (2 or more devices share the highest usage value from the 8 values), would you like a random value from all 8 devices or only from the primary devices? I presumed the latter. Also, I'd like to know 1) the number of primary devices (theoretically from 1-8) and 2) the highest usage value upon which the decision for 'primary device' was based.

HTH,

Ruben

*****Create sample data*****.

new file.
set seed 1.

input program.
loop id=1 to 10.
do repeat u=s2r_1 to s2r_8.
compute u=rnd(rv.f(3,10)).
if u>5 u=0.
end repeat.
end case.
end loop.
end file.
end input program.

*****Since we'll FUBAR the data, let's first save a copy*****.

sav out 'c:/ori_data.sav'./*Make sure you have permission to save directly in the c:/ folder.

*****Now we'll create the desired vars*****.

varstocases
/make usage from s2r_1 to s2r_8
/index=primary_device.

aggregate outfile = * mode=addvariables
/break id
/max_usage=max(usage).

select if usage=max_usage.

compute t1=rv.uni(0,1)./*Auxiliary random var to randomize the selection of primary device.

aggregate outfile = * mode=addvariables
/break=id
/no_primary_devices=n
/t2=max(t1).

select if t1=t2.

*****And now we'll merge the new vars back into the old data*****.

match files file *
/file='c:/ori_data.sav'
/by id
/drop usage t1 t2.
exe.



> Date: Sat, 7 Jul 2012 13:34:04 -0700

> From: [hidden email]
> Subject: Create Primary variable from 2 sets of variables
> To: [hidden email]
>
> I'm not sure I'm describing this well, so please forgive any vagueness.
>
> I have one set of variables (S1_1 to S1_8) that cover ownership of
> particular devices. This set is either 1 for owned or 0 for not owned. Then
> a second set of variables (S2R1 to S2R_8) that cover usage, with each
> variable having a value of 0 to 5, with higher values indicating more usage.
>
> I want to create a variable for the primary device - the one with the most
> usage - 'Primary'. The value would a number (1 to 8) corresponding with
> S1_1 to S1_8.
>
> I can't figure out the syntax for this. I'd be having trouble in any case,
> but the problem is more complicated by the fact that the usage responses can
> be duplicated. When there are multiple devices that could each be primary,
> I'd like to assign a random device to Primary.
>
> I can conceive of how to do it with Excel (although I haven't yet tried to
> create it) but I'm sure it could be done with SPSS if I knew how.
>
> Any suggestions would be most appreciated.
>
> Thanks
> Mike
>
> _________________________________________________________________________
> Mike Pritchard | [hidden email] | 5 Circles Research | 425-444-3410 (c)
> | 425-968-3883 (o)
> Research to help companies build products that people buy
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD