【问题标题】:How to reshape data in SPSS如何在SPSS中重塑数据
【发布时间】:2012-09-10 20:05:59
【问题描述】:

我有来自一项调查的数据。问题是这样的:

Did you do any of the following activities during your PhD

                             Yes, paid by my school. Yes, paid by me.  No. 

Attended an internationl conference?
Bought textbooks? 

数据以这种方式自动保存在电子表格中:

id conf.1 conf.2 conf.3 text.1 text.2 text.3

1    1                              1
2           1               1
3                   1       1
4                   1                    1
5               

这意味着参与者 1 参加了由她的大学支付的会议;参加者2参加了他支付的会议,参加者3没有去。

我想在单个变量中合并 conf.1、conf.2 和 conf.3 以及 text.1、text.2 和 text.3

id new.conf new.text

1   1        2
2   2        1
3   3        1
4   3        3

where the number now respresents the categories of the survey question

Thanks for your help

【问题讨论】:

标签: reshape spss


【解决方案1】:

我不确定您的描述多个响应集(您在问题的评论中link to)是否真的是您想要的。在这个例子中,你根本不需要重塑你的数据,一个简单的DO REPEAT 命令就足以让你的new.confnew.text 变量。下面的例子:

data list free /id conf.1 conf.2 conf.3 text.1 text.2 text.3.
begin data
1 1 0 0 0 1 0 
2 0 1 0 1 0 0 
3 0 0 1 1 0 0 
4 0 0 1 0 0 1 
5 0 0 0 0 0 0 
end data.
dataset name conf.
*this is to replicate missing data as specified originally.
recode conf.1 to text.3 (0 = SYSMIS)(ELSE = COPY).

compute new.conf = 0.
compute new.text = 0.
do repeat conf_list = conf.1 to conf.3 /text_list = text.1 to text.3 /#i = 1 to 3.
    if conf_list = 1 new.conf = #i.
    if text_list = 1 new.text = #i.
end repeat.

命令list all 然后产生以下输出(注意我如何将变量初始化为 0 值,不是真正需要,但我通常是如何处理的):

  id   conf.1   conf.2   conf.3   text.1   text.2   text.3 new.conf new.text

1.00     1.00      .        .        .       1.00      .       1.00     2.00
2.00      .       1.00      .       1.00      .        .       2.00     1.00
3.00      .        .       1.00     1.00      .        .       3.00     1.00
4.00      .        .       1.00      .        .       1.00     3.00     3.00
5.00      .        .        .        .        .        .        .00      .00

阅读案例数:5 列出案例数:5

您可能确实想要重塑数据,但如果 conf 和 text 列表变量相互排斥,则没有理由。如果您需要对数据进行整形,请参阅命令VARSTOCASES 用于从宽到长整形和CASESTOVARS 用于从长到宽整形的帮助。

【讨论】:

    猜你喜欢
    • 2023-03-28
    • 2020-12-23
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-25
    相关资源
    最近更新 更多