Creating a new variable with "repeating/consecutive" numbers

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

Creating a new variable with "repeating/consecutive" numbers

Sakari Lemola
Hello,

I would like to create a variable VAR1 with "repeating" numbers as in the
following example:

ID  VAR1
1   1
2   1
3   1
4   2
5   2
6   2
7   3
8   3
9   3
10  4
11  4
12  4
13  5
14  5
15  5

-> it is like a consecutive number list but each number is repeated three
times.

How to do this with syntax or macro?

Thanks very much

Sakari Lemola

=====================
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: Creating a new variable with "repeating/consecutive" numbers

Oliver, Richard
This might work. If it's "consecutive" based on ID value:

compute var1=trunc((id+2)/3).

If it's "consecutive" based on file order:

compute var1=trunc(($casenum+2)/3).

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Sakari Lemola
Sent: Sunday, August 10, 2008 6:08 AM
To: [hidden email]
Subject: Creating a new variable with "repeating/consecutive" numbers

Hello,

I would like to create a variable VAR1 with "repeating" numbers as in the
following example:

ID  VAR1
1   1
2   1
3   1
4   2
5   2
6   2
7   3
8   3
9   3
10  4
11  4
12  4
13  5
14  5
15  5

-> it is like a consecutive number list but each number is repeated three
times.

How to do this with syntax or macro?

Thanks very much

Sakari Lemola

=====================
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: Creating a new variable with "repeating/consecutive" numbers

Maguin, Eugene
This would work better.

compute var1=mod(id,3).
Recode var1(0=3).

If it's "consecutive" based on file order:

compute var1=mod($casenum,3).
Recode var1(0=3).

Gene Maguin

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