syntax - Compute mean within SPSS loop -
i need compute mean of set of ratings (var v_cr1 v_cr11) provided relevant control variable (var targ_i.1 targ_i.11) each rating satisfies condition (>=4 , not missing).
at first attempted adjust syntax found http://stackoverflow.com/questions/12711613/loop-through-items-and-sum-items-in-spss/12794702.
this used:
compute targ_vcs=0. execute. vector targ_i = targ_i.1 targ_i.11. vector targ_vc = v_cr1 v_cr11. loop #vecid = 1 11. if (targ_i(#vecid) <=4 , not missing (targ_vc((#vecid)))). compute targ_vcs= targ_vcs+ targ_vc(#vecid). end if. end loop. execute.
it seems have worked provide me sum, although returns zeroes instead of missing when conditions not satisfied, can work around that. however, sum valid mean need count of valid v_cr satisfy targ_i. data has targ_i <=4 , not missing there missing v_cr (and other way around, accounted in above code), simple count won't do.
i figure need either straightforward way compute mean within loop, way embed count in code (i've been trying no luck) or way have valid denominator mean computation on side. ideas?
new spss syntax (heck, syntax), seeming far more complicated me needs be, sure. tia!
the idea of following approach first copy variables v_cr1 v_cr11 if condition of test variables targ_i.1 targ_i.11 met, otherwise copy variable set sysmis. in second step mean of conditional copy variable computed.
* copy v_crx v_cr_ccx if targ_i.x<=4. repeat v_cr = v_cr1 v_cr11 /targ_i = targ_i.1 targ_i.11 /v_cr_cc = v_cr_cc1 v_cr_cc. if (targ_i<=4) v_cr_cc = v_cr. end repeat. compute v_cr_condmean = mean(v_cr_cc1 v_cr_cc11). execute.
Comments
Post a Comment