在 SPSS 中转置 (CaseToVars) 并使用现有变量重命名变量
Transposing (CaseToVars) in SPSS and renaming Variables with Existing Variables
数据集包含 6 个变量,例如:
StudentID Sequence Metric Score Interpretation ScoreName
a123 8.00 13 540 12 P1_AIE
a123 9.00 14 550 19 P2_AIE
a123 9.00 15 500 13 P1_BP
a124 8.00 14 450 11 P2_AIE
我最终试图将所有案例放在一行中,例如:
StudentID P1_AIE_Seq P1_AIE_Scr P1_AIE_Interp P2_AIE_Seq P2_AIE_Scr P2_AIE_Interp P1_BP_Seq etc.
a123 8.00 540 12 9.00 550 19 9.00 etc.
a124 8.00 450 11
这些学生 (StudentID) 反复完成一系列测试 (Sequence);它们的结果(Score)由一个数值(Metric)和一个字符串(ScoreName)跟踪,并附有一个数字代码用于解释每个分数(Interpretation)。
Metric 和 ScoreName 始终对应(即在所有情况下 14 = P2_AIE)。没有重复的记录。序列最初不适合用作索引,因为它在 ID 变量中重复,但为了解决这个问题,我使用:
SORT CASES BY StudentID Sequence.
compute dup = 0.
if $casenum>1 and lag(StudentID)= StudentID and lag(sequence) = Sequence dup=lag(dup)+1.
sort cases by StudentID dup Sequence.
CASESTOVARS
/ID = StudentID dup
/Index = Sequence
/GROUPBY = Index/sep="_".
我显然在错误地构建语法---这不会将单个案例放在一行中,它不会通过 ScoreName 重命名变量---甚至不确定 SPSS 是否可以在没有 python。
如有任何反馈或建议,我们将不胜感激
在您的所需输出示例中,您似乎正在使用 scorename
作为索引,在这种情况下,似乎不需要 fiddle 和 sequence
像你一样变量。
这将重新创建您的示例数据:
data list list /StudentID (a4) Sequence Metric Score Interpretation (4f3) ScoreName (a6).
begin data.
"a123" 8 13 540 12 "P1_AIE"
"a123" 9 14 550 19 "P2_AIE"
"a123" 9 15 500 13 "P1_BP"
"a124" 8 14 450 11 "P2_AIE"
end data.
现在,如果您 运行 以下内容,您将在一行中获得每个 ID 的所有数据:
sort cases by studentID ScoreName.
casestovars /id=studentID /index=ScoreName/sep="_"/groupby=index.
数据集包含 6 个变量,例如:
StudentID Sequence Metric Score Interpretation ScoreName
a123 8.00 13 540 12 P1_AIE
a123 9.00 14 550 19 P2_AIE
a123 9.00 15 500 13 P1_BP
a124 8.00 14 450 11 P2_AIE
我最终试图将所有案例放在一行中,例如:
StudentID P1_AIE_Seq P1_AIE_Scr P1_AIE_Interp P2_AIE_Seq P2_AIE_Scr P2_AIE_Interp P1_BP_Seq etc.
a123 8.00 540 12 9.00 550 19 9.00 etc.
a124 8.00 450 11
这些学生 (StudentID) 反复完成一系列测试 (Sequence);它们的结果(Score)由一个数值(Metric)和一个字符串(ScoreName)跟踪,并附有一个数字代码用于解释每个分数(Interpretation)。
Metric 和 ScoreName 始终对应(即在所有情况下 14 = P2_AIE)。没有重复的记录。序列最初不适合用作索引,因为它在 ID 变量中重复,但为了解决这个问题,我使用:
SORT CASES BY StudentID Sequence.
compute dup = 0.
if $casenum>1 and lag(StudentID)= StudentID and lag(sequence) = Sequence dup=lag(dup)+1.
sort cases by StudentID dup Sequence.
CASESTOVARS
/ID = StudentID dup
/Index = Sequence
/GROUPBY = Index/sep="_".
我显然在错误地构建语法---这不会将单个案例放在一行中,它不会通过 ScoreName 重命名变量---甚至不确定 SPSS 是否可以在没有 python。
如有任何反馈或建议,我们将不胜感激
在您的所需输出示例中,您似乎正在使用 scorename
作为索引,在这种情况下,似乎不需要 fiddle 和 sequence
像你一样变量。
这将重新创建您的示例数据:
data list list /StudentID (a4) Sequence Metric Score Interpretation (4f3) ScoreName (a6).
begin data.
"a123" 8 13 540 12 "P1_AIE"
"a123" 9 14 550 19 "P2_AIE"
"a123" 9 15 500 13 "P1_BP"
"a124" 8 14 450 11 "P2_AIE"
end data.
现在,如果您 运行 以下内容,您将在一行中获得每个 ID 的所有数据:
sort cases by studentID ScoreName.
casestovars /id=studentID /index=ScoreName/sep="_"/groupby=index.