我的数据(have)包括银行(LenderID),贷款公司(BorrowerID),以及LenderID和BorrowerID之间交易的日期(Date)。数据按照BorrowerID LenderID Date排序,如下数据片段所示。我想做的是创建一个新变量relation,对于每一个交易(Date),如果同一对LenderID和BorrowerID在之前五年内还有另外的交易(Date),那么relation等于1,其他等于0,像下边数据里的relation一样。我用下边的代码试了试,随机挑了几个结果是对的,想请各位验证下,帮忙看看有没有没想到的情况。多谢多谢另外下边的代码还报错
“NOTE: Invalid argument to function YRDIF at line 46 column 29.”
“NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to missing values. Each place is given by: (Number of times) at (Line):(Column). 404500 at 46:29”但是结果还是对的
| BorrowerID | LenderID | Date | relation |
1 | 7827 | 19870912 | 0 |
2 | 5951 | 19870901 | 0 |
2 | 6003 | 19870908 | 0 |
3 | 6127 | 19871001 | 0 |
4 | 5930 | 19870801 | 0 |
4 | 6128 | 19870801 | 0 |
6 | 5951 | 19871001 | 0 |
7 | 5951 | 19870901 | 0 |
8 | 6225 | 19951004 | 0 |
8 | 6833 | 19871001 | 0 |
9 | 6039 | 19871201 | 0 |
9 | 6834 | 19871001 | 0 |
10 | 6100 | 19870912 | 0 |
10 | 6100 | 19880630 | 1 |
11 | 5891 | 19871012 | 0 |
12 | 6075 | 19870909 | 0 |
13 | 6039 | 19880202 | 0 |
13 | 7878 | 19880201 | 0 |
14 | 6149 | 19871001 | 0 |
15 | 5875 | 19870902 | 0 |
16 | 6835 | 19870912 | 0 |
17 | 30195 | 20011019 | 0 |
17 | 69495 | 20011019 | 0 |
17 | 80167 | 20011019 | 0 |
17 | 82462 | 20011019 | 0 |
18 | 5891 | 19871012 | 0 |
18 | 5891 | 19880831 | 1 |
19 | 5891 | 19921123 | 0 |
19 | 5891 | 19931231 | 1 |
19 | 6003 | 19870612 | 0 |
19 | 6031 | 19921123 | 0 |
19 | 6531 | 19931231 | 0 |
19 | 7839 | 19870901 | 0 |
20 | 5893 | 19870912 | 0 |
20 | 5893 | 19881215 | 1 |
20 | 5978 | 19940722 | 0 |
20 | 6529 | 19930820 | 0 |
20 | 6901 | 19870101 | 0 |
21 | 7827 | 19871001 | 0 |
22 | 7845 | 19870212 | 0 |
22 | 7845 | 19871001 | 1 |
23 | 6006 | 19871001 | 0 |
23 | 6006 | 19871101 | 1 |
23 | 6842 | 19871001 | 0 |
24 | 1468 | 19900801 | 0 |
24 | 1468 | 19970120 | 0 |
24 | 1468 | 20001211 | 1 |
24 | 1468 | 20041215 | 1 |
24 | 1468 | 20041217 | 1 |
24 | 5862 | 19910405 | 0 |
24 | 5862 | 19920310 | 1 |
24 | 5862 | 19920414 | 1 |
24 | 5862 | 19920507 | 1 |
24 | 5862 | 19960105 | 1 |
24 | 5862 | 19961210 | 1 |
24 | 5862 | 19970110 | 1 |
24 | 5889 | 19871001 | 0 |
24 | 5889 | 19871118 | 1 |
24 | 5889 | 19910405 | 1 |
24 | 5889 | 19940311 | 1 |
24 | 5889 | 19960105 | 1 |
24 | 5889 | 19961210 | 1 |
24 | 5889 | 19970110 | 1 |
24 | 5889 | 20001211 | 1 |
24 | 5893 | 19901207 | 0 |
24 | 5893 | 19910405 | 1 |
24 | 5893 | 19940311 | 1 |
24 | 5893 | 19960105 | 1 |
24 | 5893 | 19961210 | 1 |
24 | 5893 | 19970110 | 1 |
