Hi All,
I know the title of the question seems confusing, but I will try to explain my problem to the best of my ability.
I currently have a dataset that looks like the following:
------------------ copy up to and including the previous line ------------------
In the dataset above, we have three vectors: the first one corresponds to an individual's identifier, the second corresponds to the year of the observation, and the third corresponds to the score that an individaul obtained. What I wish to do is to basically calculate a vector of covariances of scores for each possible pair of individuals (this will yield nC2 different unique combinations) across different years. Basically, I want to obtain the time-covariance of each possible (i,j) combination, with each term in the covariance calculation corresponding to the particular (demeaned) product of score that i and j obtained in that year, and then dividing by the number of years that (i,j) both have scores.
Any help on this is much appreciated.
Best Wishes,
Chinmay
I know the title of the question seems confusing, but I will try to explain my problem to the best of my ability.
I currently have a dataset that looks like the following:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(Identifier Year Score) 1 1990 2 1 1991 43 1 1992 3 1 1993 4 2 1990 23 2 1991 4 2 1992 32 2 1993 43 3 1990 3234 3 1991 23 3 1992 32 3 1993 32 . . . . . . end
In the dataset above, we have three vectors: the first one corresponds to an individual's identifier, the second corresponds to the year of the observation, and the third corresponds to the score that an individaul obtained. What I wish to do is to basically calculate a vector of covariances of scores for each possible pair of individuals (this will yield nC2 different unique combinations) across different years. Basically, I want to obtain the time-covariance of each possible (i,j) combination, with each term in the covariance calculation corresponding to the particular (demeaned) product of score that i and j obtained in that year, and then dividing by the number of years that (i,j) both have scores.
Any help on this is much appreciated.
Best Wishes,
Chinmay
Comment