Dear Statalisters,
I have a question concerning data manipulation in Stata.
Please consider a stylized version of my dataset:
var1 var2 var3
1 2 223
1 3 12
2 1 7544
2 3 7864
3 1 434
3 2 12334
You can think of var1 and var2 as identifying different regions in a
country and var3 could measure migration between region pairs, for example
223 persons migrate from 1 to 2. There are three regions. Migrating within
the same region is not possible, that is why there are no (1,1),(2,2) or
(3,3) observations for var1 and var2.
I would like to generate a variable var4 which should look like (or
similarly coded):
var4
1
2
1
3
2
3
var4 counts the region PAIRS: (1,2) and (2,1) are one pair, (1,3) and
(3,1) are the second pair, and (2,3) and (3,2) are the third pair.
Unfortunately, I am not sure how to do this.
My plan is to use var4 to calculate the net migration volume between
regions, which means I want to calculate:
223-7544
12-434
7864-12334
I wonder if I have to generate sub-datasets and use the -cross- command.
Is there perhaps an easier way to generate var4? Or is the variable var4
not necessary at all to calculate the net migration?
Thank you very much in advance,
Falko
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/