Loops

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

Loops

Khaleel Hussaini
 Hi Listers!
    I have a simple query that requires me to go through 22 statements to
create a new variable. Here is where I need help.
Age (11 categories) and Gender (2 categories). I want to have a new variable
called Gen_Age which combines information from these two variables. Females
(1 to 14), Males (1 to 14), Females (15 to 17) Males (15 to 17) etc. Can we
use a vector and/or a loop function to create new variable with 22
categories? Mind you I don't want dummy variables. Best,
SKH.

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

Jerabek Jindrich
Hi,

Do REPEAT should work. I suppose that You have 11 variables coded 1/0 for age and Gender coded 1/2.

DO REPEAT a = age1 to age11 /  n = 1 to 11.
IF a = 1 and gender=1 NewVar=n.
IF a = 1 and gender=2 NewVar=20+n.
END REPEAT.

The above not tested syntax should create a new variable NewVar, coded 1-11 for men and 21-31 for women.


> ------------ Původní zpráva ------------
> Od: Khaleel Hussaini <[hidden email]>
> Předmět: Loops
> Datum: 02.7.2008 01:55:03
> ----------------------------------------
>  Hi Listers!
>     I have a simple query that requires me to go through 22 statements to
> create a new variable. Here is where I need help.
> Age (11 categories) and Gender (2 categories). I want to have a new variable
> called Gen_Age which combines information from these two variables. Females
> (1 to 14), Males (1 to 14), Females (15 to 17) Males (15 to 17) etc. Can we
> use a vector and/or a loop function to create new variable with 22
> categories? Mind you I don't want dummy variables. Best,
> SKH.
>
> =====================
> 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
>
>
>

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

Dennis Deck
In reply to this post by Khaleel Hussaini
From your brief description the simplest way would be:

COMPUTE GenAge = Gender*10 + Age .

This creates a combined variable with values 11, 12, 21, 22.
(Note that your example suggests that age is categorical [1=1 to 14,
2=15 to 17].)
Only downside is that there are gaps in the values.


Dennis Deck, PhD
RMC Research Corporation
111 SW Columbia Street, Suite 1200
Portland, Oregon 97201-5843
voice: 503-223-8248 x715
voice: 800-788-1887 x715
fax:  503-223-8248
[hidden email]


-----Original Message-----
From: Khaleel Hussaini [mailto:[hidden email]]
Sent: Tuesday, July 01, 2008 4:51 PM
Subject: Loops

 Hi Listers!
    I have a simple query that requires me to go through 22 statements
to create a new variable. Here is where I need help.
Age (11 categories) and Gender (2 categories). I want to have a new
variable called Gen_Age which combines information from these two
variables. Females
(1 to 14), Males (1 to 14), Females (15 to 17) Males (15 to 17) etc. Can
we use a vector and/or a loop function to create new variable with 22
categories? Mind you I don't want dummy variables. Best, SKH.

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