selecting one household member and macros?

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

selecting one household member and macros?

Stefan Gildemeister DIGEST
Hi all -  I have a data file that collects certain information for a number
of people in a household (1 thru 9 up to the total nbr of people in the HH).
 So for instance, var1 thru var9 refer to race for up to nine household
members.  One of the members is the "target," but it can be person 1 thru 9
(up to the max nbr of people in the HH).  How can I create var_t so that it
uses the race information for the target.  And is there a way of doing this
for a number of variables in one step?  "Targ_no" identifies the target by
assigning the person number (1 thru 9).

I've experimented with macros, but it doesn't seem to work out so far.
Thanks for any ideas.

Best,
SG

=====================
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: selecting one household member and macros?

Richard Ristow
At 12:48 PM 6/4/2008, Stefan Gildemeister DIGEST wrote:

>I have information for a number of people in a household (1 thru 9
>up to the total nbr of people in the HH).  So for instance, var1
>thru var9 refer to race for up to nine household members.

OK: You have 'wide' data organization -- all individuals in one
record. This one can be easier with 'long' organization, with one
record per individual, but it's pretty easy as you have it.

>One of the members is the "target".  "Targ_no" identifies the target
>by the person number (1 thru 9). How can I create var_t so that it
>uses the race information for the target?  And for a number of
>variables in one step?

Here's a VECTOR solution (not tested) for
. var1 to var9 -> var_t,
. sex1 to sex9 -> sex_t,
. age1 to age9 -> age_t

It requires that var1 to var9, sex1 to sex9, and age1 to age9 be
contiguous in the file, so they can be defined as vectors. (If they
aren't, a DO REPEAT solution can work.) And it does no error
checking, so it'll give warning messages if Targ_no is not an integer
in the range 1-9.

VECTOR
   var = var1 TO var9/
   sex = sex1 TO sex9/
   age = age1 TO age9.

COMPUTE var_t = var(Targ_no).
COMPUTE sex_5 = sex(Targ_no).
COMPUTE age_5 = age(Targ_no).



>I've experimented with macros, but it doesn't seem to work out so far.

Generally better to stick with open code first. Anything that can be
done with macros can be done with open code, though often less
compactly. You could package the above as a macro, allowing calls like

!TgtVal(var1 TO var9,var_t).
!TgtVal(age1 TO age9,age_t).
!TgtVal(sex1 TO sex9,sex_t).

but I doubt it's worth the trouble.

-Best of luck,
  Richard

=====================
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: selecting one household member and macros?

Richard Ristow
At 04:58 PM 6/5/2008, Stefan Gildemeister wrote, off-list:

>Thanks, Richard.  This is brilliant and so straightforward, worked
>like a charm!

Thanks!

>Am I pushing my luck asking for tips on the DO REPEAT
>version?  Defining the variables to evaluate is less the question,
>but how do I reference the Targ_no in the computation?  Sorry if
>this is a really fundamental question.

Roughly, like this (written hastily and not tested, so don't be
surprised at syntax problems):

DO REPEAT
    INDEX = 1 TO 9
   /VAR   = var1 var2 var3 var4 var5 var6 var7 var8 var9.
.  IF INDEX = Targno  Var_t = VAR.
END REPEAT.

=====================
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: selecting one household member and macros?

Stefan Gildemeister DIGEST
works as well.  Thanks for the great help.

>>> Richard Ristow <[hidden email]> 06/09/2008 12:23 AM >>>
At 04:58 PM 6/5/2008, Stefan Gildemeister wrote, off-list:

>Thanks, Richard.  This is brilliant and so straightforward, worked
>like a charm!

Thanks!

>Am I pushing my luck asking for tips on the DO REPEAT
>version?  Defining the variables to evaluate is less the question,
>but how do I reference the Targ_no in the computation?  Sorry if
>this is a really fundamental question.

Roughly, like this (written hastily and not tested, so don't be
surprised at syntax problems):

DO REPEAT
    INDEX = 1 TO 9
   /VAR   = var1 var2 var3 var4 var5 var6 var7 var8 var9.
.  IF INDEX = Targno  Var_t = VAR.
END REPEAT.

=====================
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