|
The following code is very simple to run in SPSS:
PARTIAL CORR /VARIABLES = cmpi7 cta_1 BY cta_2 ctb_1 ctc_1.
However, I need code or a macro to do the first variable (cmpi7) by every possible combination of the other variables. So the next one might be cmpi7 cta_1 BY ctb_1 ctc_1. And another one could be cmpi7 ctb_1 BY ctc_1.
I would think some sort of a macro would best help here but I do not think I have found the perfect macro for doing permutations within a command in SPSS.
Please help! Thank you very much in advance.
Zachary
|
|
Hi Zachary,
try this macro (and of course change the directory in the
call in the last row of the macro if needed):
define permut (outfile = !charend('|') / statvars = !charend('|') / byvars = !cmdend ). * creates PARTIAL CORR commands with all permutations of byvars on left & right side of BY. * statvars are on the left side of BY only * the output is saved in outfile .
* count byvars and create quoted variables. !let !countstr = "" !let !kv = "" !do !i !in (!byvars) !let !countstr = !concat(!countstr, "x") !let !kv = !concat(!kv ," ", !quote(!i)) !doend !let !cnt = !length(!countstr) .
* create a SPSS data file with the permutations in rows. input program. - vector r (!cnt, f1). - loop #n = 1 to 2**!cnt . - loop #i = 1 to !cnt . - compute r(#i) = rnd((-1)**(trunc((#n-1)/(2**(#i-1)) )) + 1) / 2. - end loop. - end case. - end loop. - end file. end input program. !let !rmax = !concat("r",!cnt ) compute #s = sum(r1 to !rmax ). select if #s > 0 and #s < !cnt . * because the 0000 and 1111 permutations do not give sense here. exe. * create the needed commands. vector r = r1 to !rmax . string command (a250). compute command = concat("PARTIAL CORR /VARIABLES = ", !quote(!statvars)). do repe i = 1 to !cnt / v = !kv . - if r(i) = 0 command = concat(rtrim(command), " ", v). end repe. compute command = concat(rtrim(command), " BY"). do repe i = 1 to !cnt / v = !kv . - if r(i) = 1 command = concat(rtrim(command), " ", v). end repe. compute command = concat(rtrim(command), "."). WRITE OUTFILE = !quote(!outfile) /command . exe. !enddefine.
permut outfile = c:/temp/partcorr.sps | statvars = cmpi7 | byvars = cta_1 cta_2 ctb_1 ctc_1 .
Best, Jan From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Zachary Feinstein Sent: Monday, October 04, 2010 11:26 PM To: [hidden email] Subject: Need for Permutation Code to Run Partial Correlations Multiple Times The following code is very simple to run in SPSS:
PARTIAL CORR /VARIABLES = cmpi7 cta_1 BY cta_2 ctb_1 ctc_1.
However, I need code or a macro to do the first variable (cmpi7) by every
possible combination of the other variables. So the next one might be
cmpi7 cta_1 BY ctb_1 ctc_1. And another one could be cmpi7 ctb_1 BY
ctc_1.
I would think some sort of a macro would best help here but I do not think
I have found the perfect macro for doing permutations within a command in
SPSS.
Please help! Thank you very much in advance.
Zachary
_____________ Tato zpráva
a všechny připojené
soubory jsou důvěrné a určené výlučně adresátovi(-ům). Jestliže nejste
oprávněným adresátem, je zakázáno jakékoliv zveřejňování, zprostředkování nebo
jiné použití těchto informací. Jestliže jste tento mail dostali neoprávněně,
prosím, uvědomte odesilatele a smažte zprávu i přiložené soubory. Odesilatel
nezodpovídá za jakékoliv chyby nebo opomenutí způsobené tímto
přenosem.
P Are you sure that you
really need a print version of this message and/or its attachments? Think about
nature.
|
| Free forum by Nabble | Edit this page |
