如何在SPSS中重塑数据

时间:2012-09-10 20:06:00

标签: reshape spss

我有调查数据。问题如下:

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

1 个答案:

答案 0 :(得分:0)

我不确定您的描述是否有多个响应集(您对问题的评论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从长到宽整形。