问题描述
正如标题所说。
A B
1 Car
2 Bike
3 Van
1 Car
3 Van
A 列包含数值。 B 列包含标签。
我想告诉 SPSS 取值 1,并为它分配标签“汽车”(等等),因为通常手动完成:
VALUE LABELS
1 "Car"
2 "Bike"
3 "Van".
Execute.
解决方法
下面的语法将自动创建一个新语法,按照您的描述添加值标签。
在开始之前,我正在重新创建您发布的示例数据以进行演示:
data list list/A (f1) B (a10).
begin data
1 "Car"
2 "Bike"
3 "Van"
1 " Car"
3 "Van"
end data.
dataset name orig.
现在我们开始工作:
* first we aggregate the data to get only one line for every value/label pair.
dataset declare agg.
aggregate out=agg /break A B /nn=n.
dataset activate agg.
* now we use the data to create a syntax file with the value label commands.
string cat (a50).
compute cat=concat('"',B,'"').
write out="yourpath\my labels syntax.sps" /"add value labels A ",A,cat,".".
execute.
* getting back to the original data we can now execute the syntax.
dataset activate orig.
insert file="yourpath\my labels syntax.sps".