I currently have data that look like ( a much larger version) of the following:
----------------------- copy starting from the next line -----------------------
Here, ID is a person's identifier, X1 is variable 1 and X2 is variable 2. What I want is to expand this dataset and create unique pairings of individuals first. This means that for instance, individual 1 will be paired with individual 2 and 3 (2 data points) and 2 will be paired with 1 and 3 (2 datapoints) and 3 will be paired with 1 and 2 (2 datapoints). Thereafter, I wish to sum over the variables X1 for each individual with the individual that she is paired with. So for instance, this new variable X3, for the first 2 datapoints, will consist of a sum of the value of X1 for individual 1 with X2 of that of individual 2 (1st Data point) and the sum of the value of X1 for individual 1 with X2 of that of individaul 3 (2nd datapoint). This has to be done for all individuals in the dataset. I envision a dataset that looks like the following:
Any help is much appreciated!
----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(ID X1 X2) 1 10 40 2 20 50 3 30 60 end
Here, ID is a person's identifier, X1 is variable 1 and X2 is variable 2. What I want is to expand this dataset and create unique pairings of individuals first. This means that for instance, individual 1 will be paired with individual 2 and 3 (2 data points) and 2 will be paired with 1 and 3 (2 datapoints) and 3 will be paired with 1 and 2 (2 datapoints). Thereafter, I wish to sum over the variables X1 for each individual with the individual that she is paired with. So for instance, this new variable X3, for the first 2 datapoints, will consist of a sum of the value of X1 for individual 1 with X2 of that of individual 2 (1st Data point) and the sum of the value of X1 for individual 1 with X2 of that of individaul 3 (2nd datapoint). This has to be done for all individuals in the dataset. I envision a dataset that looks like the following:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(Individual Paired Sum) 1 2 60 1 3 70 2 1 60 2 3 80 3 1 70 3 2 90 end
Any help is much appreciated!