I have only a limited knowledge of SPSS syntax and can't figure out
how to do this. I would be so grateful for any advice.
The data look something like the following (except with 1,000 cases
and 30 variables).
As in the real data set, in this small one, the difference in the
count of 0's and 1's varies across variables.
In var1, there are two 0's and one 1 (therefore one randomly selected
0 should be recoded to missing).
In var2, there are four 0's and two 1's (so two randomly selected 0's
should be recoded to missing).
In var3, there is one 0 and two 1's (so one randomly selected 1 should
be recoded to missing).
DATA LIST LIST / var1 TO var5.
BEGIN DATA
,0, , ,
1,0, , ,
, ,1,0,1
, ,0,0,
0,1, , ,
, , ,1,
, ,1, ,
0,0, , ,0
,1, ,1,
,0, , ,
END DATA.00 cases and 30 variables).
I look forward to any suggestions for how to do this! Thank you!
CD "C:/temp".
DATA LIST LIST / var1 TO var5.
BEGIN DATA
,0, , ,
1,0, , ,
, ,1,0,1
, ,0,0,
0,1, , ,
, , ,1,
, ,1, ,
0,0, , ,0
,1, ,1,
,0, , ,
END DATA.
COMPUTE ID=$CASENUM.
SAVE OUTFILE="data.sav".
DEFINE !doVars(vars=!CMDEND)
!DO !var !IN (!vars)
DATASET CLOSE ALL.
NEW FILE.
GET FILE="data.sav" /KEEP=ID !var.
COMPUTE is0= (!var=0).
COMPUTE is1= (!var=1).
COMPUTE draw=UNIFORM(1).
AGGREGATE
/nb0 nb1 =SUM(is0 is1).
DO IF nb0>nb1.
RECODE !var (1=0)(0=1).
END IF.
SORT CASES !var (D).
IF $CASENUM LE ABS(nb0 - nb1) !var=$SYSMIS.
SORT CASES BY ID.
DO IF nb0>nb1.
RECODE !var (1=0)(0=1).
END IF.
SAVE OUTFILE=!QUOTE(!CONCAT(!var,".sav")) /KEEP=ID !var.
!DOEND
MATCH FILES !DO !var !IN (!vars) /FILE=!QUOTE(!CONCAT(!var,".sav")) !
DOEND
/BY=ID.
TITLE Frequencies after replacement of the required number of values.
FREQ VAR=!vars.
SAVE OUTFILE="final data file.sav".
!ENDDEFINE.
SET MPRINT=YES /PRINTBACK=YES.
!doVars vars=var1 var2 var3 var4 var5.