SPSS:检查/中是否存在某个变量的元素也是另一个变量的元素
SPSS: check if an element of some variable exist in / is also element of another variable
我想计算一个变量,它检查变量 v1
的元素是否也包含在另一个变量 v2
中。
让我们假设以下示例:
我有以下三个变量:group-ID (gID)、person-ID (pID)(组内)和 lender-ID (LID),借钱人ID
然后我想创建一个新变量 (loa) 来指示每个人是否借钱给其他人。或者换句话说,如果pID的元素也出现在LID.
中
例如,请参阅以下 table:
+-----+-----+-----+ +-----+-----+-----++-----+
+ gID | pID | LID | + gID | pID | LID || loa |
+-----+-----+-----+ +-----+-----+-----++-----+
+ 1 | 1 | 2 | + 1 | 1 | 2 ++ 0 |
+ 1 | 2 | - | + 1 | 2 | - || 1 |
+ 1 | 3 | 4 | + 1 | 3 | 4 || 0 |
+ 1 | 4 | - | + 1 | 4 | - || 1 |
+-----+-----+-----+ => +-----+-----+-----++-----+
+ 2 | 1 | - | + 2 | 1 | - || 1 |
+ 2 | 2 | 4 | + 2 | 2 | 4 || 0 |
+ 2 | 3 | 4 | + 2 | 3 | 4 || 0 |
+ 2 | 4 | 1 | + 2 | 4 | 1 || 1 |
如何在 SPSS 中完成此操作?
这里的基本思想是创建一个数据集,它是 LID 中出现的一组元素(对于每个 groupId),这意味着在这个数据集中,groupiD 和 LID(借钱人的 Id)的每个组合) 只存在一次。
一种方法是使用 AGGREGATE
命令:
* Name the original dataset, so it can be addressed later.
DATASET NAME main.
* Create a data set with unique combinations of groupID and LoanID.
* Bonus: Count how many loans a person has given.
DATASET DECLARE set.
AGGREGATE OUTFILE=set
/BREAK gID LID
/count_loans = N.
此数据集现在可以用作查找来识别借钱的人 (pID)。 MATCH FILES
命令完成工作:
* Indicate wether pID has lent money (exist as LID in the set data) or not.
* Bonus: Add variable which counts the loans of that person.
* Note: "main" has to be sorted by "gID pID"
* and "set" has to be sorted by "gID LID".
DATASET ACTIVATE main.
MATCH FILES
/FILE *
/TABLE set
/RENAME (lId=pID)
/IN loa
/BY gID pID.
EXECUTE.
我想计算一个变量,它检查变量 v1
的元素是否也包含在另一个变量 v2
中。
让我们假设以下示例: 我有以下三个变量:group-ID (gID)、person-ID (pID)(组内)和 lender-ID (LID),借钱人ID
然后我想创建一个新变量 (loa) 来指示每个人是否借钱给其他人。或者换句话说,如果pID的元素也出现在LID.
中例如,请参阅以下 table:
+-----+-----+-----+ +-----+-----+-----++-----+
+ gID | pID | LID | + gID | pID | LID || loa |
+-----+-----+-----+ +-----+-----+-----++-----+
+ 1 | 1 | 2 | + 1 | 1 | 2 ++ 0 |
+ 1 | 2 | - | + 1 | 2 | - || 1 |
+ 1 | 3 | 4 | + 1 | 3 | 4 || 0 |
+ 1 | 4 | - | + 1 | 4 | - || 1 |
+-----+-----+-----+ => +-----+-----+-----++-----+
+ 2 | 1 | - | + 2 | 1 | - || 1 |
+ 2 | 2 | 4 | + 2 | 2 | 4 || 0 |
+ 2 | 3 | 4 | + 2 | 3 | 4 || 0 |
+ 2 | 4 | 1 | + 2 | 4 | 1 || 1 |
如何在 SPSS 中完成此操作?
这里的基本思想是创建一个数据集,它是 LID 中出现的一组元素(对于每个 groupId),这意味着在这个数据集中,groupiD 和 LID(借钱人的 Id)的每个组合) 只存在一次。
一种方法是使用 AGGREGATE
命令:
* Name the original dataset, so it can be addressed later.
DATASET NAME main.
* Create a data set with unique combinations of groupID and LoanID.
* Bonus: Count how many loans a person has given.
DATASET DECLARE set.
AGGREGATE OUTFILE=set
/BREAK gID LID
/count_loans = N.
此数据集现在可以用作查找来识别借钱的人 (pID)。 MATCH FILES
命令完成工作:
* Indicate wether pID has lent money (exist as LID in the set data) or not.
* Bonus: Add variable which counts the loans of that person.
* Note: "main" has to be sorted by "gID pID"
* and "set" has to be sorted by "gID LID".
DATASET ACTIVATE main.
MATCH FILES
/FILE *
/TABLE set
/RENAME (lId=pID)
/IN loa
/BY gID pID.
EXECUTE.