【问题标题】:Combining add cases and add variables by merging files in SPSS通过在SPSS中合并文件来组合添加案例和添加变量
【发布时间】:2017-05-03 14:52:30
【问题描述】:

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

我已经阅读了以下帖子,但这并没有完全回答我的问题: 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 中是否可行?如果是这样,我该怎么做?

提前致谢!

【问题讨论】:

    标签: syntax add spss


    【解决方案1】:

    这样就可以了:

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

    但请注意,在运行比赛之前,两个文件都需要按 paid id 排序。

    用您的示例数据进行演示:

    *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
    

    【讨论】:

    • 非常感谢。这对我很有帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多