Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Obtaining immigration per country from bilateral migration flows data

    Hello everyone !

    I am currently using a dataset of bilateral migration flows between countries. Here is an example to illustrate the shape of my dataset.

    YEAR ORIG DEST NB
    2000 A B 50
    2000 A C 25
    2000 B A 10
    2000 B C 20
    2000 C A 5
    2000 C B 0
    2005 A B 60
    2005 A C 10
    2005 B A 10
    2005 B C 5
    2005 C A 0
    2005 C B 0


    From this information, I want to aggregate the number of migrants (NB) in order to obtain emigration (EMIG) the total number of migrants leaving the country of origin (ORIG) and immigration (IMMIG) total number of migrants arriving in the country of origin.

    YEAR ORIG EMIG IMMIG
    2000 A 75 15
    2000 B 30 50
    2000 C 5 45
    2005 A 70 10
    2005 B 15 60
    2005 C 0 15


    I managed to get the emigration with the following line :

    Code:
    bysort YEAR ORIG : egen EMIG = sum(NB)
    But I do not manage to get the immigration by country of origin. Only by the country of destination.

    Has anyone any input to help me solve this issue?

    Thank you !


    RJ

  • #2
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int year str1(orig dest) byte nb
    2000 "A" "B" 50
    2000 "A" "C" 25
    2000 "B" "A" 10
    2000 "B" "C" 20
    2000 "C" "A"  5
    2000 "C" "B"  0
    2005 "A" "B" 60
    2005 "A" "C" 10
    2005 "B" "A" 10
    2005 "B" "C"  5
    2005 "C" "A"  0
    2005 "C" "B"  0
    end
    
    rename (orig dest) (orig1 orig2)
    g n=_n
    reshape long orig ,i(n)
    
    egen em = total(nb) if _j==1, by(orig year)
    egen im = total(nb) if _j==2, by(orig year)
    
    collapse (max) em im, by(year orig)
    
    list, clean
    
           year   orig   em   im  
      1.   2000      A   75   15  
      2.   2000      B   30   50  
      3.   2000      C    5   45  
      4.   2005      A   70   10  
      5.   2005      B   15   60  
      6.   2005      C    0   15

    Comment


    • #3
      Thank you so much Øyvind for your help !
      Even if I did not formulate my question well, it is very helpful and I can solve my issue now.

      Comment

      Working...
      X