现有数据如下, 三个column (title,authors(不同的name用|隔开),number_authors)
Title Authors Number_authors
Title 1 Name A | Name B 2
Title 2 Name A | Name B | Name C 3
Title 3 Name A | Name C | Name E | Name Z 4
TITLE 4 NAME A 1
TITLE 5 NAME F | NAME Z 2
..
大概有20000个observations,其中
1. title是unique的
2. number_authors 取值从1-200.
现在想做的是,对每一个observation生成一系列variables(5个):at_least_x_authors_repeat. X从1-5取整数值. 变量取值0或1
也就是:at_least_1_authors_repeat; at_least_2_authors_repeat;at_least_3_authors_repeat;at_least_4_authors_repeat;
at_least_5_authors_repeat.
变量描述了在这组数据中有多少作者是重复的
变量举例描述: 比如at_least_2_authors_repeat:title3有name A, name C, name E, name Z 四个author 如果其中至少两个名字在别的observation里也同时出现过,那么at_least_2_authors_repeat = 1, 如果任意两个名字在其他observation里都没有同时出现过,那么at_least_2_authors_repeat = 0.
从目前数据看来,A 和 C 在title 2 中出现过,所以title 2 和title3 的at_least_2_authors_repeat取值为1.
同样的,对于at_least_3_authors_repeat,我们需要检验至少三个.
这个程序应该怎样实现的?小弟已经冥思苦想很久了,仍然没有头绪,希望各位指点一二,谢谢!