Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: data manipulation: pairs of variables


From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: data manipulation: pairs of variables
Date   Wed, 27 Jul 2005 12:30:54 -0400

Falko said

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.
...
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


clear
input var1 var2 var3
1 2 223
1 3 12
2 1 7544
2 3 7864
3 1 434
3 2 12334
end
g reg1 = cond(var1>var2,var1,var2)
g reg2 = min(var1,var2)
replace var3 = cond(var1>var2,-var3,var3)
collapse (sum) var3, by(reg1 reg2)
l


Kit Baum, Boston College Economics
http://ideas.repec.org/e/pba1.html

*
* 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/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index