Hi All,
I have data that resembles the following:
---------------------- copy starting from the next line -----------------------
In the above, each row corresponds to a particular country pair (I,J) and their bilateral trade, for each year. For instance, row 1 corresponds to 1's trade with 2 for the year 1990. What I want to obtain is the average of all possible pairwise combinations of trade for each year.The following is what I have in mind:
I felt that this would do the trick, but I think it may be an issue, because there will be a lot of duplicates for M1, which will arise from the fact that each I can potentially arise numerous times in the sample, by year. One way to do this by brute force would be to temporarily save the dataset, drop all the variables except I and Year, drop duplicates and then calculate M2. Is there any other way of doing this?
Thanks,
CS
I have data that resembles the following:
---------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(I J Trade Year) 1 2 123 1990 1 3 21 1990 1 4 2 1990 1 5 123 1990 2 1 123 1990 2 3 123 1990 2 4 12 1990 2 5 123 1990 3 1 123 1990 3 2 213 1900 3 4 123 1990 4 1 123 1990 4 2 123 1990 4 3 123 1990 1 2 123 1991 1 3 123 1991 2 1 123 1991 2 4 123 1991 3 1 213 1991 3 2 123 1991 end
In the above, each row corresponds to a particular country pair (I,J) and their bilateral trade, for each year. For instance, row 1 corresponds to 1's trade with 2 for the year 1990. What I want to obtain is the average of all possible pairwise combinations of trade for each year.The following is what I have in mind:
Code:
by year I (J), sort: egen M1=mean(Trade) by year (I), sort: egen M2=mean(M1)
I felt that this would do the trick, but I think it may be an issue, because there will be a lot of duplicates for M1, which will arise from the fact that each I can potentially arise numerous times in the sample, by year. One way to do this by brute force would be to temporarily save the dataset, drop all the variables except I and Year, drop duplicates and then calculate M2. Is there any other way of doing this?
Thanks,
CS
Comment