Macro to create ratio variables

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

Macro to create ratio variables

jing zhang-2
Hello, I am trying to create 15 ratio variables.

I will highly appreciate any ideas to use MACRO (or loop) command to do this job in SPSS!

Thanks,
Jing Zhang
economist at NCUA
*****************************************
COMPUTE X1R= (X1_98-X1_97)/Y .

COMPUTE X2R= (X2_98-X2_97)/Y .

COMPUTE X15R= (X15_98-X15_97)/Y .

 
 
Reply | Threaded
Open this post in threaded view
|

Re: Macro to create ratio variables

Richard Ristow
At 11:43 AM 5/1/2009, jing zhang wrote:

I will highly appreciate any ideas to use MACRO (or loop) command to do this job in SPSS!
*****************************************
COMPUTE X1R= (X1_98-X1_97)/Y .
...
COMPUTE X15R= (X15_98-X15_97)/Y .

Assuming that X1_97 to X15_97 are contiguous in your file, and that X1_98 to X15_98 are also contiguous, then (untested),

DO REPEAT   X_97  = X1_97 TO X15_97
           /X_98  = X1_98 TO X15_98
           /Ratio = X1R   TO X15_R.
.   COMPUTE Ratio= (X_98-X_97)/Y .
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: Macro to create ratio variables

Albert-Jan Roskam
In reply to this post by jing zhang-2
Hi,

In Python, it's simply:

import spss
for i in range(1, 16):
    spss.Submit("COMPUTE X%sR=(X1_98-X%s_97)/Y." % (i, i))

Cheers!!
Albert-Jan

--- On Fri, 5/1/09, jing zhang <[hidden email]> wrote:

> From: jing zhang <[hidden email]>
> Subject: Macro to create ratio variables
> To: [hidden email]
> Date: Friday, May 1, 2009, 5:43 PM
> Hello, I am trying
> to create� 15 ratio variables.
>
> I will highly
> appreciate any ideas to use MACRO (or loop) command to do
> this job in SPSS!
>
> Thanks,
> Jing
> Zhang
> economist at
> NCUA
> *****************************************
>
> COMPUTE X1R=
> (X1_98-X1_97)/Y .
> COMPUTE X2R=
> (X2_98-X2_97)/Y .
> …
> COMPUTE X15R=
> (X15_98-X15_97)/Y .
> �
> �
>

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