【问题标题】:define variable labels in a loop for existing variables SPSS在循环中为现有变量定义变量标签 SPSS
【发布时间】:2016-05-08 01:36:54
【问题描述】:

我有一些变量

V1 V2 V3

我想在循环中给变量标签:

variable labels V1 "Person 1".
variable labels V2 "Person 2".
...

应该是一件容易的事,但据我所知,我不能使用 DO REPEAT(因为它不是数据转换),而是必须编写一个宏。

(见:How can I loop through variables in SPSS? I want to avoid code duplication

来自 R 和 STATA,我真的不知道如何开始。

这个问题的答案: Variable labels in SPSS Macro 对我来说似乎不同,因为创建了新变量而不是重新标记现有变量。

【问题讨论】:

    标签: loops variables label spss


    【解决方案1】:

    如果您安装了 SPSS Python 集成包,则可以在 Python 中运行循环。

    以下代码创建variable labels V# "Person #". 行,其中“#”是从 1 到 3 的数字。

    BEGIN PROGRAM.
    import spss
    
    for i in range(1, 4):
        spss.Submit('variable labels V%s "Person %s".' % (i, i))
    END PROGRAM.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-21
      • 1970-01-01
      • 2015-11-07
      • 1970-01-01
      • 2017-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多