通过合并SPSS中的文件来合并添加案例和添加变量 [英] Combining add cases and add variables by merging files in SPSS

查看:502
本文介绍了通过合并SPSS中的文件来合并添加案例和添加变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想合并不同的SPSS文件。 PAID表示不同的人。这些文件还包含指示测量时刻的变量ID。因此ID = 1表示数据是测量1的结果(ID = 2;测量2等)。但是,并非所有数据文件都包含相同的测量时刻。

I would like to merge different SPSS files. The PAID indicates different persons. The files also contain the variable ID which indicates the moment of measurement. So ID=1 means that the data are results of measurement one (ID=2 ; measurement two etc.). However, not all data files contain the same moments of measurement.

我已经阅读了以下帖子,但是并没有完全回答我的问题:
包含ID变量重复的文件合并文件> SPSS-合并具有ID变量重复的情况和新的case / variables的文件

I have already read the following post, but that has not completely answered my question: SPSS - merging files with duplicate cases of ID variable and new cases/variables

示例数据文件

数据文件1:

PAID  ID  X1  X2  X3  X4
1     1   3   4   4   5
2     1   3   4   5   6
3     1   3   4   4   6
4     1   .   .   .   .

数据文件2:

PAID  ID  X5  X6  X7  
1     1   1   1   2
1     2   1   2   1
2     1   1   2   2
2     2   2   2   2
3     1   1   1   1
3     2   1   .   .
4     1   1   1   1
4     2   2   2   2

我想要以下结果:

PAID  ID  X1  X2  X3  X4  X5  X6  X7
1     1   3   4   4   5   1   1   2
1     2   .   .   .   .   1   2   1
2     1   3   4   5   6   1   2   2
2     2   .   .   .   .   2   2   2
3     1   3   4   4   6   1   1   1
3     2   .   .   .   .   1   .   .
4     1   .   .   .   .   1   1   1
4     2   .   .   .   .   2   2   2

我想我必须使用一些函数来组合大小写和添加变量。但是,这在SPSS中可行吗?如果是这样,我该怎么办?

I think I have to use some combination of the functions add cases and add variables. However, is this possible within SPSS? And if so, how can I do this?

预先感谢!

推荐答案

这将完成工作:

match files /file='path\DataFile1.sav' /file='path\DataFile2.sav'/by paid id.

不过请注意,两个文件都必须按 paid id ,然后再运行比赛。

Please note though, both files need to be sorted by paid id before running the match.

用示例数据进行演示:

*first preparing demonstration data.
DATA LIST list/paid id x1 to x4 (6f).
begin data.
1,1,3,4,4,5
2,1,3,4,5,6
3,1,3,4,4,6
4,1, , , ,
end data.
* instead of creating the data, you can can get your original data:
* get file="path\file name 1.sav".
sort cases by paid id.
dataset name DataFile1.


DATA LIST list/paid id x5 to x7 (5f).
begin data.
1,1,1,1,2
1,2,1,2,1
2,1,1,2,2
2,2,2,2,2
3,1,1,1,1
3,2,1, ,
4,1,1,1,1
4,2,2,2,2
end data.
sort cases by paid id.
dataset name DataFile2.

match files /file=DataFile1 /file=DataFile2/by paid id.
exe.

结果如下:

paid id x1  x2  x3  x4  x5  x6  x7
1    1  3   4   4   5   1   1   2
1    2                  1   2   1
2    1  3   4   5   6   1   2   2
2    2                  2   2   2
3    1  3   4   4   6   1   1   1
3    2                  1       
4    1                  1   1   1
4    2                  2   2   2

这篇关于通过合并SPSS中的文件来合并添加案例和添加变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆