Hi folks,
I am having trouble figuring out how to run the following (I think egen mean should be able to do it):
I am trying to generate a variable IV which will equal to the mean, by year, of invest for dest countries that are contig with a given orig country. For example, the first 3 observations are for year 1 and orig country A. Since A is contig with B and D (but not C), I would like the new variable IV to be the mean of 14 and 20 for the first 3 observations. Another example: observations 4-6 are for year 1 and orig country B. Since B is contig with A and C (but not D), I would like the new variable IV to be the mean of 11 and 18 for observations 4-6.
Any help would be greatly appreciated.
Thank you.
I am having trouble figuring out how to run the following (I think egen mean should be able to do it):
year | orig | dest | contig | invest |
1 | A | B | 1 | 11 |
1 | A | C | 0 | 12 |
1 | A | D | 1 | 13 |
1 | B | A | 1 | 14 |
1 | B | C | 1 | 15 |
1 | B | D | 0 | 16 |
1 | C | A | 0 | 17 |
1 | C | B | 1 | 18 |
1 | C | D | 1 | 19 |
1 | D | A | 1 | 20 |
1 | D | B | 0 | 21 |
1 | D | C | 1 | 22 |
2 | A | B | 1 | 61 |
2 | A | C | 0 | 62 |
2 | A | D | 1 | 63 |
2 | B | A | 1 | 64 |
2 | B | C | 1 | 65 |
2 | B | D | 0 | 66 |
2 | C | A | 0 | 67 |
2 | C | B | 1 | 68 |
2 | C | D | 1 | 69 |
2 | D | A | 1 | 70 |
2 | D | B | 0 | 71 |
2 | D | C | 1 | 72 |
Any help would be greatly appreciated.
Thank you.
Comment