SPSS - 与ID变量和新案例/变量的重复案例合并文件 [英] SPSS - merging files with duplicate cases of ID variable and new cases/variables

查看:702
本文介绍了SPSS - 与ID变量和新案例/变量的重复案例合并文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多年的商店访问管理数据集,我试图合并到一个 ID 变量之下。

I have an administrative dataset for store visits from multiple years that I am trying to merge into one under the ID variable.

每个数据集都有不同商店访问期间发生的 ID 的副本,由 Date 注释。一些最新的数据文件也包含在旧数据文件中的新变量( Y )。来自不同年份的数据集还将包含不同的情况,由不同的 ID 表示。另外,一些变量对于每种情况可能是相同的,但是在不同的日期。我想要合并的文件保留这些重复。

Each dataset has duplicates of an ID that occur during different store visits, annotated by Date. Some of the more recent data files also have new variables (Y) not contained in the old data files. Datasets from different years will also contain different cases indicated by different ID. Also, some variables may be the same for each case but at different dates. I want the merged file to retain these duplicates.

示例数据文件:

文件1

ID Date X
1  3    4
1  5    3
2  1    4

文件2

ID Date X  Y
1  6    4  2
1  7    1  5
2  8    4  7
3  7    2  3

我希望合并文件继续列出所有重复的案例,如下所示:

I want the merged file to continue listing ALL duplicate cases, as such:

ID Date X  Y
1  3    4  .
1  5    3  .
1  6    4  2
1  7    1  5
2  1    4  .
2  8    4  7
3  7    2  3

然后我计划重组( CASESTOVARS / AUTOFIX = 0 )合并文件,使其如下所示:

I then plan to restructure (CASESTOVARS /AUTOFIX=0) the merged file so that it looks like this:

ID Date.1 Date.2 Date.3 Date.4  X.1  X.2  X.3  X.4  Y.1  Y.2  Y.3  Y.4
1  3      5      6      7       4    3    4    1    .    .    2    5
2  1      8      .      .       4    4    .    .    .    7    .    .
3  7      .      .      .       2    .    .    .    3    .    .    .

然而,我在初始合并过程中遇到困难。我已经尝试查找最合适的方式来合并文件,当它们都有重复的情况下,以确保没有数据丢失的过程中。似乎添加变量方法会导致重复变量丢失的值。

I am having trouble with the initial merging process, however. I have tried looking up the safest way to merge files when they both have duplicate cases in order to make sure no data are lost in the process. It seems that the "Add Variables" method results in lost values for duplicate variables.

谢谢!

编辑:如果我使用添加变量功能并使用 ID Date 变量作为关键变量,这有助于避免删除重复的案例?

If I used the "Add Variables" function and used both the ID and Date variables as the key variables, would that help avoid deletion of duplicate cases?

推荐答案

为什么不尝试添加案例而不是添加变量?如果在同一日期没有出现相同的ID,则应该使用 casestovars 可以正常工作。

Why not try add cases instead of add variables? if there are no occurrences of the same Id with the same date it should work OK with the casestovars.

如果有这种情况,你需要考虑你想要做什么,然后才能执行 casestovars

一种方法是通过ID和DATE进行聚合,并决定是否要例如加起来这个案例的数据变量。

If there are such cases, you'll need to think what you want to do with them before you can proceed with the casestovars.
One way would be to aggregate by ID and DATE and decide if you want to e.g. add up the data vars for this case.

这篇关于SPSS - 与ID变量和新案例/变量的重复案例合并文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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