如何在SPSS中填写基础变量之前和上限变量(数据中指定)之后的缺失数据?

问题描述 投票:0回答:1

我的评估数据在特定基本项目下方和指定上限项目之后缺少数据。我尝试为基础项目下方的所有缺失数据填写值 1,并为上限项目之后的所有缺失数据填写值 0。数据如下:

screenshot of table

  • 第 1 行:第 4 至 10 项需要 0
  • 第 2 行:第 9 项和第 10 项需要 0
  • 第 3 行:第 1 项和第 2 项需要 1 秒,第 9 项和第 10 项需要 0 秒
  • 第 4 行:第 1 项需要 1 个
  • 第 5 行:第 5 项到第 10 项需要 0
spss
1个回答
0
投票

您可以循环项目(例如使用

do repeat
)并将项目名称与 Basal 和 Ceiling 变量中的文本进行比较,但这里有一个更优雅的方法(无论如何),使用重组:

* turning the item numbers into real numbers.
if basal<>"" basalN=number(char.substr(basal,5),F2).
if ceiling<>"" ceilingN=number(char.substr(ceiling,5),F2).

* creating an id for later use in restructure.
compute id=$casenum.

* now we restructure to long format so we have the items in a column instead of a row, and a string index with item name.
varstocases make val from item1 to item10/index=item(val)/null=keep.

* now we can complete the missing items as requested.
if missing(val) and number(char.substr(item,5),F2)<basalN val=1.
if missing(val) and number(char.substr(item,5),F2)>ceilingN val=0.

* now we've completed the operation we can restructure to original form.
casestovars id=id/index=item/fix=basal ceiling basalN ceilingN/sep="".
© www.soinside.com 2019 - 2024. All rights reserved.