Date: Wed, 12 Nov 2003 16:29:19 +0200
Reply-To: Martins.Liberts@csb.gov.lv
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Martins.Liberts@csb.gov.lv
Subject: Re: macro
Content-type: text/plain; charset=us-ascii
There is an error.
!let !a=!a+1 will not work
you have to use
!let !a=!len(!con(!bla(!a)," "))
Sorry!
Hi Marcos,
*Not tested.
DEFINE !DoIt (var1=!charend("/") var2 = !CMDEND)
!let !a=0
!let !b=0
!DO !i !IN (!var1)
!let !a = !a+1
!DO !J !IN (!var2)
!let !b=!b+1
!IF (!a !EQ !b)
!THEN
CORRELATIONS
/VARIABLES=!i !j
/PRINT=TWOTAIL NOSIG
/MISSING=PAIRWISE .
!IFEND
!DOEND
!DOEND
!ENDDEFINE.
!DoIt var1 var2 var3 / var4 var5 var6.
Actualy I am also looking for possibility to define pairs with macro right
now.
I had such idea:
define !varn() nod bzd e46 !enddefine.
define !vard() visi ekakt nod !enddefine.
define !n()
!let !n=0
!do !var !in (!eva(!varn))
!let !n=!len(!con(!bla(!n)," "))
!doend
!n
!enddefine.
define !ratio()
!let !vnl=!eva(!varn)
!let !vdl=!eva(!vard)
!do !i=1 !to !eva(!n)
!let !vn=!head(!vnl)
!let !vd=!head(!vdl)
comp !con("rat",!i,"_1")=!con(!vn,"_1")/!con(!vd,"_1").
comp !con("rat",!i,"_t")=!con(!vn,"_t")/!con(!vd,"_t").
!let !vnl=!sub(!vnl,!len(!con(!bla(!len(!vn))," ")))
!let !vdl=!sub(!vdl,!len(!con(!bla(!len(!vd))," ")))
!doend
!enddefine.
!ratio
*But it seems that yours is shorter. And if number of pairs is not big, it
will not take mach time to compute it.
Thanks!
Martins
--
Martins Liberts
Central Statistical Bureau of Latvia
address: Lacplesa iela 1, Riga, LV-1301, Latvia
phone: 371-7366877
email: Martins.Liberts@csb.gov.lv
Marcos Sanches
<marcos_sanches@g To: SPSSX-L@LISTSERV.UGA.EDU
allup.com> cc:
Sent by: Subject: Re: macro
"SPSSX(r)
Discussion"
<SPSSX-L@LISTSERV
.UGA.EDU>
12.11.2003 16:01
Please respond to
Marcos Sanches
Thanks very much Jim!
Your first suggestion is just what I want, and in fact will work for
some
cases, but my variables names are not always like those, they can be very
different sometimes. In this case the !CONCAT wouldn't work. A natural
extension of my macro would be something like
DEFINE !DoIt (var1=!CMDEND ; var2 = !CMDEND)
Is this possible? How do I call the macro in this case? What to do inside
the macro so that SPSS correlate the element 'i' of var1 with the element i
(and only it) of var2? It would be something much like this:
DEFINE !DoIt (var1=!CMDEND var2 = !CMDEND)
!DO !i !IN (!var1).
compute #a = #a+1.
!DO !J !IN (!var2).
compute #b=#b+1.
!IF (#a !EQ #b)
!THEN
CORRELATIONS
/VARIABLES=!i var_x
/PRINT=TWOTAIL NOSIG
/MISSING=PAIRWISE .
!IFEND
!DOEND
!DOEND.
!ENDDEFINE.
The problema is that it gives me a error message because of the second
!CMDEND. Also, I don't know if the 'compute' and the variables #a and #b
will be acepted...
TIA
Marcos
-----Original Message-----
From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU]On Behalf Of
Marks, Jim
Sent: Tuesday, November 11, 2003 8:42 PM
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: Re: macro
Marcos:
You can nest "!DO" commands within a macro--
make sure you have the appropriate number of "!DOEND" statements.
For your example, you don't need a second !DO, however. The pairs of
variables share a common root and number-- they differ on "a" and "b" at
the
end of the variable name.
You can use "!CONCAT" to construct variables names with a var#a var#b
pattern. This will give you bivariate correlations var1a with var1b up to
var#a with var#b (I tested with 4 paired variables).
** sample data for testing.
DATA LIST FREE /id var1a var1b var2a var2b var3a var3b var4a var4b.
BEGIN DATA
1 .5 .5 .4 .6 2 3 55 57
2 .3 .4 .5 .6 4 7 45 44
3 .5 .45 .5 .55 7 9 35 20
4 .33 .3 .4 .8 2 1 20 11
5 .7 .79 .3 .5 3 5 66 54
END DATA.
** numeric looping macro.
DEFINE !DoItnb ().
!DO !i = 1 !TO 4
CORRELATIONS
/VARIABLES=!CONCAT(var,!i,a) !CONCAT(var,!i,b)
/PRINT=TWOTAIL NOSIG
/MISSING=PAIRWISE .
!DOEND.
!ENDDEFINE.
!DOItnb.
If you want to correlate var1a with var2b that will require a different
macro. This will create bivariate correlations
var1a with var1b --> var1a with var4b
var2a with var2b --> var2a with var4b
etc.
DEFINE !DoItge ().
!DO !i = 1 !TO 4
!DO !j = 1 !TO 4
!IF (!j !GE !i)
!THEN
CORRELATIONS
/VARIABLES=!CONCAT(var,!i,a) !CONCAT(var,!j,b)
/PRINT=TWOTAIL NOSIG
/MISSING=PAIRWISE .
!IFEND
!DOEND
!DOEND.
!ENDDEFINE.
!DoItge.
This will generate thousands of correlations in a 500 variable set-- use it
with caution :)
Jim Marks
Senior Market Analyst
LodgeNet Entertainment Corporation
-----Original Message-----
From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU]On Behalf Of
Marcos Sanches
Sent: Tuesday, November 11, 2003 10:48 AM
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: macro
Hi listers!
Supose the following macro:
DEFINE !DoIt (var=!CMDEND)
!DO !i !IN (!var).
CORRELATIONS
/VARIABLES=!i var_x
/PRINT=TWOTAIL NOSIG
/MISSING=PAIRWISE .
!DOEND.
!ENDDEFINE.
Now, if I write
!DoIt var = var1 var2 var3 var4 var5 var6.
Then I'll get the Correlation procedure of all these variables with var_x.
Supose now I have to get correlations between a lot of variables pairs.
Like
this:
var1a with var1b
var2a with var2b
var3a with var3b
....
var500a with var500b
All I want is a macro almost like the above, but I need to enter with two
vectors of variables, not just one. var_x in the above macro must be anoter
macro variable, like !j.
How do I acomplish that?
TIA
Marcos