Hi ftr,
sorry if this syntax is long but I did not have any suitable sav file
at hand.
******* Create fake data N=200
************************************************.
DATA LIST FREE /dummy (F3.0).
BEGIN DATA
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6
7 8 9 0 1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6
7 8 9 0 1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6
7 8 9 0 1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6
7 8 9 0 1 2 3 4 5 6 7 8 9 0
END DATA.
**** Make 10 variables with random data r1 TO r10.
VECTOR r (10).
LOOP #i = 1 TO 10.
+ COMPUTE r(#i) = RV.UNIFORM(0, 100).
END LOOP.
EXE.
**** Make 10 dichotomic vars m1 TO m10.
DO REPEAT r = r1 TO r10 / p = 27 67 80 34 11 60 21 44 8 59 / m = m1 TO m10.
+ DO IF MOD(RND(r), 5) NE 0.
+ COMPUTE m = r LE p.
+ END IF.
END REPEAT.
EXE.
VAR LAB m1 "Sports" /m2 "Food" /m3 "Cinema" /m4 "Books" /m5 "Art" /m6
"Music" /m7 "Nature"
/m8 "TV" /m9 "Politics" /m10 "Automobiles".
*** Make fake breakdown var.
COMPUTE segment = dummy GT 3.
VAR LAB segment "Segment".
VAL LAB segment 0 "Hi" 1 "Lo".
******* End create fake data
**************************************************.
DESCRIPTIVES m1 TO m10.
**** Table 1. SPSS only.
*TABLES
/MDGROUP = hobbies "" m1 TO m10 (1)
/PTOTAL = pt "Total"
/TABLE = hobbies BY pt + segment
/STATISTICS CPCT(hobbies (PCT5.1) "": segment)
/TITLE="Don't do this at home with PSPP".
*** Convert dichotomic MD to numeric MR.
*** I create 10 vars here but usually the MR answers are less than the
MD codes.
COMPUTE #k = 0.
VECTOR mr (10).
DO REPEAT md = m1 TO m10.
+ COMPUTE #k = #k + 1.
+ DO IF md.
+ COMPUTE #done = 0.
+ LOOP #i = 1 TO 10.
+ DO IF SYSMIS(mr(#i)) AND NOT #done.
+ COMPUTE mr(#i) = #k.
+ COMPUTE #done = 1.
+ END IF.
+ END LOOP.
+ END IF.
END REPEAT.
EXECUTE.
VAL LAB mr1 TO mr10 1 "Sports" 2 "Food" 3 "Cinema" 4 "Books" 5 "Art" 6
"Music" 7 "Nature"
8 "TV" 9 "Politics" 10 "Automobiles".
**** Table 2 should be same as Table 1. SPSS only.
*TABLES
/MRGROUP = hobbies "" mr1 TO mr10
/PTOTAL = pt "Total"
/TABLE = hobbies BY pt + segment
/STATISTICS CPCT(hobbies (PCT5.1) "": segment).
*** Convert numeric MR to dichotomic MD.
VECTOR bin (10) /* highest code in MR vars */.
DO REPEAT mr = mr1 TO mr10.
+ DO IF NOT MISSING(mr).
+ COMPUTE bin(mr) = 1.
+ END IF.
END REPEAT.
RECODE bin1 TO bin10 (SYSMIS=0) (1=100).
VAR LAB bin1 "Sports" /bin2 "Food" /bin3 "Cinema" /bin4 "Books" /bin5
"Art" /bin6 "Music" /bin7 "Nature"
/bin8 "TV" /bin9 "Politics" /bin10 "Automobiles".
**** Same result again.
*TABLES
/MDGROUP = hobbies "" bin1 TO bin10 (100)
/PTOTAL = pt "Total"
/TABLE = hobbies BY pt + segment
/STATISTICS CPCT(hobbies (PCT5.1) "": segment).
*** PSPP alternatives.
** Would be nice if PSPP honoured FORMATS.
FORMATS bin1 TO bin10 (PCT5.1) /* does nothing ?*/.
MEANS bin1 TO bin10 BY segment.
SORT CASES BY segment.
SPLIT FILE BY segment.
DESCRIPTIVES bin1 TO bin10.
SPLIT FILE OFF.
** My favourite. Finish off in spreadsheet.
AGGREGATE OUTFILE = * /BREAK = segment
/bin1 TO bin10 = MEAN(bin1 TO bin10).
FLIP.
SAVE TRANSLATE /OUTFILE = "table.txt"
/TYPE=TAB /FIELDNAMES /REPLACE.
Regards
frans
On 10/01/2015 13:29, F. Thomas wrote:
This sounds interesting. Can you please translate this into a
practical example because I don't understand all of your moves ?
Cheers,
ftr
On 09/01/2015 21:21, Frans Houweling wrote:
Hi Matthias,
I use good ol' (SPSS 14) TABLES, so I don't usually save MRSETS but
define them on the fly with /MRGROUP; I guess CTABLES give similar
results.
Often I prefer to translate my MR variables to MD format like this
(suppose codes with max code 100, and suppose max 10 answers):
VECTOR bin (100) /* max code */.
DO REPEAT mr = mr1 TO mr10 /* input vars */.
+ DO IF NOT MISSING(mr).
+ COMPUTE bin(mr) = 1.
+ END IF.
END REPEAT.
RECODE bin1 TO bin100 /* max code again */ (SYSMIS=0) (1=1) /* or
for readability (1=100) */.
The tedious part is converting VAL LAB 1 "Alfa Romeo" 2 "Audi" etc.
into VAR LAB bin1 "Alfa Romeo" /bin2 "Audi" etc., but once this is
done you can use MEANS or DESCRIPTIVES in combination with SPLIT FILE
to live without (C)TABLES and without SPSS(C).
HTH
frans
_______________________________________________
Pspp-users mailing list
Pspp-users@gnu.org
https://lists.gnu.org/mailman/listinfo/pspp-users
_______________________________________________
Pspp-users mailing list
Pspp-users@gnu.org
https://lists.gnu.org/mailman/listinfo/pspp-users