I thought this would be rather simple, but I can't figure it out.
I have a dataset that includes twin pairs. I want to make a twin variable (e.g. variable X is person i's value for Y, and variable X2 is the value of person i's twin for Y) so that I can do MZ and DZ twin correlations. I have family ID and twin status. I tried to do it by doing various versions of by X: replace twinvariable[_N]=_N-1, etc., but it isn't quite doing it. Is there some way to tell Stata, "look in this variable Y-defined group. If there are two cases in this group that have the same value for variable X, insert a value in variable X2 that consists of the value of the other pair case"?
Many thanks
I have a dataset that includes twin pairs. I want to make a twin variable (e.g. variable X is person i's value for Y, and variable X2 is the value of person i's twin for Y) so that I can do MZ and DZ twin correlations. I have family ID and twin status. I tried to do it by doing various versions of by X: replace twinvariable[_N]=_N-1, etc., but it isn't quite doing it. Is there some way to tell Stata, "look in this variable Y-defined group. If there are two cases in this group that have the same value for variable X, insert a value in variable X2 that consists of the value of the other pair case"?
Many thanks
Comment