I have three variables: v1, v2, v3:
v1 contains a numeric ID. It indicates about which person information is available.
v2 also contains numeric IDs that identify persons. v2, however, does not contain the ID of the person about whom information is available, but the ID of the person who provided that information. Thus, in the case where a person A testified about herself, v1 contains the same ID as v2. In the case where a person B testified about a person A, v1 contains the ID of A, v2 contains the ID of B.
v3 contains a response code. It can have characteristics like "completed", "not encountered" or "refused".
The response code is only present in those lines in which v1 == v2 (i.e. lines in which a person has provided information about him/herself).
In the lines where v1 != v2, the response code is missing.
For all lines where the response code is missing, I want to check if the person giving information (their ID is in v2) occurs in another line in v1 and if so, I want to assign their response code in the line where the person is giving information about another person.
Minimal example:
The result is:
I am looking for code like:
if (v3 == "."){
a = value of v2.
Search in v1 till you find value a.
Take value of v3 in that row and assign to v3 in initial row.
}
It should generate:
Thank you very much in advance!
v1 contains a numeric ID. It indicates about which person information is available.
v2 also contains numeric IDs that identify persons. v2, however, does not contain the ID of the person about whom information is available, but the ID of the person who provided that information. Thus, in the case where a person A testified about herself, v1 contains the same ID as v2. In the case where a person B testified about a person A, v1 contains the ID of A, v2 contains the ID of B.
v3 contains a response code. It can have characteristics like "completed", "not encountered" or "refused".
The response code is only present in those lines in which v1 == v2 (i.e. lines in which a person has provided information about him/herself).
In the lines where v1 != v2, the response code is missing.
For all lines where the response code is missing, I want to check if the person giving information (their ID is in v2) occurs in another line in v1 and if so, I want to assign their response code in the line where the person is giving information about another person.
Minimal example:
Code:
set obs 10 egen v1 = seq(), from(1) to(10) egen v2 = seq(), from(1) to(5) gen v3 = "completed" replace v3 = "." if v1 > 5 replace v3 = "refused" if v1 == 2 replace v3 = "not encountered" if v1 == 4
v1 | v2 | v3 |
1 | 1 | completed |
2 | 2 | refused |
3 | 3 | completed |
4 | 4 | not encountered |
5 | 5 | completed |
6 | 1 | . |
7 | 2 | . |
8 | 3 | . |
9 | 4 | . |
10 | 5 | . |
I am looking for code like:
if (v3 == "."){
a = value of v2.
Search in v1 till you find value a.
Take value of v3 in that row and assign to v3 in initial row.
}
It should generate:
v1 | v2 | v3 |
1 | 1 | completed |
2 | 2 | refused |
3 | 3 | completed |
4 | 4 | not encountered |
5 | 5 | completed |
6 | 1 | completed |
7 | 2 | refused |
8 | 3 | completed |
9 | 4 | not encountered |
10 | 5 | completed |
Thank you very much in advance!
Comment