Hello, apologies if something is done incorrectly, this is my first time posting to STATALIST.
I am looking to create a new variable based on the condition of other variables. For example, I have an ID which equals 280. That ID has four neighbors, which all also have their own unique IDs. Let's say 281, 282, 283, and 284. Now we can expand this, to another ID lets say 284. It has neighbors of 280, 285, 286, and 287. Further, let's say we have another variable called x which has the value of 2 at ID 280. What I am looking to do is create a value for another variable called y which is equal to 1 if variable x is greater than 0 and my IDs match. Below is a table to help visualize this.
As you can see, because var_x is greater than 0 and ID 284 and 280 are neighbors, var_y is given a value of 1. This is a much simpler example of what I am looking to do but the logic is the same. So at ID 280 var_x is greater than 0 and neighbor4 equals 284. Thus at ID 284 var_y should equal 1 as seen in the table above. The issue I am having is that I cannot input numbers like one would replace var_y = 1 if ID == 280 because the data set is very large and these values are not consistent.
If anyone has some ideas on how to implement this that would be extremely helpful!
Thank you and all the best,
Adam
I am looking to create a new variable based on the condition of other variables. For example, I have an ID which equals 280. That ID has four neighbors, which all also have their own unique IDs. Let's say 281, 282, 283, and 284. Now we can expand this, to another ID lets say 284. It has neighbors of 280, 285, 286, and 287. Further, let's say we have another variable called x which has the value of 2 at ID 280. What I am looking to do is create a value for another variable called y which is equal to 1 if variable x is greater than 0 and my IDs match. Below is a table to help visualize this.
ID | var_x | neighbor1 | neighbor2 | neighbor3 | neighbor4 | var_y |
280 | 281 | 282 | 283 | 284 | 1 | |
284 | 2 | 280 | 285 | 286 | 287 | 0 |
As you can see, because var_x is greater than 0 and ID 284 and 280 are neighbors, var_y is given a value of 1. This is a much simpler example of what I am looking to do but the logic is the same. So at ID 280 var_x is greater than 0 and neighbor4 equals 284. Thus at ID 284 var_y should equal 1 as seen in the table above. The issue I am having is that I cannot input numbers like one would replace var_y = 1 if ID == 280 because the data set is very large and these values are not consistent.
If anyone has some ideas on how to implement this that would be extremely helpful!
Thank you and all the best,
Adam
Comment