SPSS:根据分数汇总多个变量分数 [英] SPSS: summing up multiple variable scores depending on their score

查看:371
本文介绍了SPSS:根据分数汇总多个变量分数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

tl; dr:我需要首先将一组变量二等分为0/1,然后将这些值求和.我需要针对14x8变量执行此操作,因此我正在寻找一种循环处理方法.

tl;dr: I need to first dichotomize a set of variables to 0/1, then sum up these values. I need to do this for 14x8 variables, so I am looking for a way to to this in a loop.

大家好,

我有一个非常具体的问题,需要您的帮助:

I have a very specific problem I need your help with:

问题描述: 在我的数据集中,我有14组,每组8个变量(例如a1到a8,b1到b8,c1到c8等),得分范围是1到6.请注意,这些变量是非连续的,字符串变量介于两者之间它们(我出于其他目的需要).

Description of problem: In my dataset I have 14 sets of 8 variables each (e.g. a1 to a8, b1 to b8, c1 to c8, etc.) with scores ranging from 1 to 6. Note that the variables are non-contiguous, with string variables in between them (which I need for a different purpose).

我知道要为每组这些变量(例如scoreA,scoreB,scoreC)计算分数.分数应根据以下规则计算:

I know want to compute scores for each set of these variables (e.g. scoreA, scoreB, scoreC). The score should be computed according the following rule:

scoreA = 0.
If a1 > 1 then increment scoreA by 1.
If a2 > 1 then increment scoreA by 1.
... etc.

示例: 数据集:

1 5 6 3 2 1 1 5

1 5 6 3 2 1 1 5

1 1 1 3 4 6 2 3

1 1 1 3 4 6 2 3

得分:

5

5

我以前的尝试: 我知道我可以通过重新编码变量以将其二等分然后对这些值求和来完成此任务.这对我来说有两个很大的缺点:首先,它创建了许多我不需要的新变量.其次,这是一个非常繁琐且重复的任务,因为我需要执行同一任务的多组变量(具有不同的变量名称).

My previous attempts: I know I could do this task by first recoding the variables to dichotomize them, and then sum up these values. This has two large drawbacks for me: Firstly it creates a lot of new variables which I don't need. Secondly it is a very tedious and repetitive task since I have multiple sets of variables (which have different variable names) with which I need to do the same task.

我看了看用VECTOR命令进行的DO REPEAT和LOOP,但是我似乎还不完全了解它们是如何工作的.我无法将在线阅读的其他示例中的解决方案转移到我的问题上. 我将对仅循环一组变量并执行任务的解决方案感到满意,然后针对其他13组变量适当调整语法.希望你能帮帮我.

I took a look at the DO REPEAT and LOOP with VECTOR commands, but I seem to not fully understand how they work. I was not able to transfer solutions from other examples I read online to my problem. I would be happy with a solution that only loops through one set of variables and does the task, then I would adjust the syntax appropriately for my other 13 sets of variables. Hope you can help me out.

亲切的问候, 大卫

推荐答案

请参阅两种解决方案:一种在每个集合上循环,第二种是在一组集合上循环的宏:

See two solutions: one loops over each of the sets, the second is a macro which loops over a list of sets:

* creating some sample data.
DATA LIST list/a1 to a8 b1 to b8 c1 to c8 hello1 to hello8.
BEGIN DATA
1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 2 1 1 1 1 1 3 3 3 1 1 1 1 4 4 4 4 
1 1 1 1 2 3 4 5 1 1 1 2 3 4 1 0 0 0 0 0 1 2 1 2 3 2 1 2 3 2 1 6
END DATA.

* solution 1: a loop for each set (example for sets a, b and c).
compute scoreA=0.
compute scoreB=0.
compute scoreC=0.
do repeat 
   a=a1 a2 a3 a4 a5 a6 a7 a8
   /b=b1 b2 b3 b4 b5 b6 b7 b8
   /c=c1 c2 c3 c4 c5 c6 c7 c8./* if variable names are consecutive replace with "a1 to a8" etc'.
 compute scoreA=scoreA+(a>1).
 compute scoreB=scoreB+(b>1).
 compute scoreC=scoreC+(c>1).
end repeat.
execute.

对14个不同的集合执行此操作并不有趣,因此,假设您的集合始终被命名为$ 1到$ 8,则可以使用以下宏:

Doing this for 14 different sets is no fun, so assuming your sets are always named $1 to $8, you can use the following macro:

define DoSets (SetList=!cmdend)
 !do !set !in (!SetList)
   compute !concat("Score_",!set)=0.
   do repeat !set=!concat(!set,"1") !concat(!set,"2") !concat(!set,"3")      !concat(!set,"4") !concat(!set,"5") !concat(!set,"6") !concat(!set,"7")           !concat(!set,"8").
     compute !concat("Score_",!set)=!concat("Score_",!set)+(!set>1).
   end repeat.
 !doend
 execute.
!enddefine.

* now call the macro and list all set names.
DoSets  SetList= a b c hello.

这篇关于SPSS:根据分数汇总多个变量分数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆