Carlotta Guaragna Vincenzo Maccarrone Samuel Nocito

Simulation models for economics

Project work on

"Should I stay or should I go."

 

The applet requires Java 5 or higher. Java must be enabled in your browser settings. Mac users must have Mac OS X 10.4 or higher. Windows and Linux users may obtain the latest Java from Oracle's Java site.


Here you can find an introduction to the Should I stay or should I go application.


powered by NetLogo

view/download model file: should_i_stay_or_should_i_go.nlogo

WHAT IS IT?

In this model, we try to study how people migrate. In order to do so, we will consider both exogenous and endogenous variable that can influence, respectively, their decisions to leave their birthplace and their decisions to come back.

HOW IT WORKS

The first step is to make agents deciding whether to leave or not their country of origin according to a rule that asses their current situation and the potential situation that they would find abroad.
The second step consists in letting agents decide whether to come back to their country of origin after a certain number of years spent abroad. Again, this decision will be taken according to a rule that considers actual and potential wellbeing of the agent.
The process will take place over a period of 25 years.

HOW TO USE IT

Users of the model may choose through the sliders the size of the population and the dimension of each family. They can also choose the distribution of incomes across the population (setting the mean and the standard deviation).
Using the choosers they can set the barrier of entry that the migrant will face and the integration level of the migrant in the host country. Moreover, they can choose the (political) stability of the outcoming countries.
The users are let free whether to show or not the links between the relatives.
Finally, they can choose through the inputs the probability according to which the skills are distributed across the population.

THINGS TO NOTICE

After the “setup”, you can see the pioneer already distributed in the host countries, while their relatives are placed in the country of origin.
After the “go”, agents will start to move and reach their relatives in the host countries. As agents start to rejoin their relatives, the user will see that the pioneers will increase their size to testify the increase in the size of the family rejoined.
From a certain point in time onward, the agents will start to comeback to their birthplace.
At the end of the process, the user can appreciate the variation in the remittances received by the outcoming areas and the changes in the growth rates of the incoming countries following the emigration process.

THINGS TO TRY

We suggest to look at the experiments in our paper.

EXTENDING THE MODEL

People interested in developing this model might find interesting to simulate the effect of a crisis in the incoming areas. A crisis might happen at the beginning of the emigration process as well as in the middle. Of course, the timing will have a great importance in determining the effects of the crisis.
Moreover, we did not let the possibility for the migrants to borrow money in order to finance their departures. One might find interesting to create this opportunity.

CREDITS AND REFERENCES

Dalen, H.P. van & Groenewold, G. & Fokkema, T., 2005. “Remittances and their effect on
emigration intentions in Egypt, Morocco, and Turkey.”

CODE

globals [ MoroccoBlock TurkeyBlock EgyptBlock AsiaBlock EuropeBlock MiddleEastBlock OutcomingCountries IncomingAreas
          M_gdp E_gdp T_gdp
          Eu_gdp MiddleEast_gdp Asia_gdp 
          M_RemittancesReceived  E_RemittancesReceived  T_RemittancesReceived
          M_ConsumedRemittances E_ConsumedRemittances T_ConsumedRemittances
          r_M r_E r_T r_Eu r_MiddleEast r_Asia 
          M_gdp_t-1 E_gdp_t-1 T_gdp_t-1 Eu_gdp_t-1 MiddleEast_gdp_t-1 Asia_gdp_t-1 ]

breed [Moroccans Moroccan]
breed [Egyptians Egyptian]
breed [Turkishes Turkish]

Moroccans-own [M_FamilyNumber]
Egyptians-own [E_FamilyNumber]
Turkishes-own [T_FamilyNumber]

undirected-link-breed [familylinks familylink]

turtles-own [ age status gender skills income dist wage remittances RemittancesReceived MyFamilyPW PotentialWage PotentialWealth  
              years integration SavingsAbility SavingsNumRelatives InvestedRemittances ConsumedRemittances InvestedRemittances_t-1
              MySituation1 MySituation2 MyPotentialSituation1 MyPotentialSituation2 ]


to setup 
        
 clear-all
 reset-ticks
 world
 generate
 variable
 
end 

to world                               ; divide the world into 6 blocks
  
   set EuropeBlock patches with [pxcor > 0 and pycor >= 6 ]  ask EuropeBlock  [ set pcolor 86 ]
   set MiddleEastBlock patches with [ pxcor > 0 and pycor < 6 and pycor > -6 ]  ask MiddleEastBlock [ set pcolor 96 ]
   set AsiaBlock patches with [ pxcor > 0 and pycor <= -6 ] ask AsiaBlock [ set pcolor 106 ]
   set MoroccoBlock patches with [ pxcor <= 0 and pycor >= 6 ]  ask MoroccoBlock  [ set pcolor 16 ] 
   set EgyptBlock patches with [ pxcor <= 0 and pycor < 6 and pycor > -6 ] ask EgyptBlock [set pcolor 26 ]
   set TurkeyBlock patches with [ pxcor <= 0 and pycor <= -6 ]  ask TurkeyBlock  [ set pcolor 46 ] 
   set IncomingAreas patches with [ pxcor > 0 ] 
   set OutcomingCountries patches with [ pxcor <= 0 ]  
    
end

to generate                           ; create popultation, pioneers and familylinks; assign gender, age, status to all agents and the years spent abroad to pioneers
  
  create-Moroccans (Morocco_population)
  ask Moroccans [move-to one-of MoroccoBlock set shape "person" set color black set status "NonMigrant"]
  
  let x 1
  repeat (Morocco_population / NumRelatives) [                                                                                
     ask n-of (NumRelatives) Moroccans with [M_FamilyNumber = 0] [
       set M_FamilyNumber x create-familylinks-with other Moroccans with [M_FamilyNumber = [M_FamilyNumber] of myself]]
     ask n-of (NumRelatives / 2) Moroccans with [M_FamilyNumber = x][set gender 1]                                        
     if NumRelatives = 6 [ask n-of (1) Moroccans with [M_FamilyNumber = x][set age "old"] 
       ask n-of (2) Moroccans with [M_FamilyNumber = x] with [age !="old"][set age "adult"]
       ask n-of (3) Moroccans with [M_FamilyNumber = x] with [age !="old"] with [age != "adult"][set age "young"]]
     if NumRelatives = 9 [ask n-of (2) Moroccans with [M_FamilyNumber = x][set age "old"] 
       ask n-of (3) Moroccans with [M_FamilyNumber = x] with [age !="old"][set age "adult"]
       ask n-of (4) Moroccans with [M_FamilyNumber = x] with [age !="old"] with [age != "adult"][set age "young"]]
     if NumRelatives = 12 [ask n-of (3) Moroccans with [M_FamilyNumber = x][set age "old"] 
       ask n-of (4) Moroccans with [M_FamilyNumber = x] with [age !="old"][set age "adult"]
       ask n-of (5) Moroccans with [M_FamilyNumber = x] with [age !="old"] with [age != "adult"][set age "young"]]
     ask one-of Moroccans with [M_FamilyNumber = x] with [gender = 1] with [age !="old"][set status "Migrant" set years 0 move-to one-of IncomingAreas]
     set x x + 1]

  create-Egyptians (Egypt_population)
  ask Egyptians [move-to one-of EgyptBlock set shape "person" set color black set status "NonMigrant"]
  
  set x 1                                                                               
  repeat (Egypt_population / NumRelatives) [
     ask n-of (NumRelatives) Egyptians with [E_FamilyNumber = 0] [
       set E_FamilyNumber x create-familylinks-with other Egyptians with [E_FamilyNumber = [E_FamilyNumber] of myself]]
     ask n-of (NumRelatives / 2) Egyptians with [E_FamilyNumber = x][set gender 1]                                        
     if NumRelatives = 6 [ask n-of (1) Egyptians with [E_FamilyNumber = x][set age "old"] 
       ask n-of (2) Egyptians with [E_FamilyNumber = x] with [age !="old"][set age "adult"]
       ask n-of (3) Egyptians with [E_FamilyNumber = x] with [age !="old"] with [age != "adult"][set age "young"]]
     if NumRelatives = 9 [ask n-of (2) Egyptians with [E_FamilyNumber = x][set age "old"] 
       ask n-of (3) Egyptians with [E_FamilyNumber = x] with [age !="old"][set age "adult"]
       ask n-of (4) Egyptians with [E_FamilyNumber = x] with [age !="old"] with [age != "adult"][set age "young"]]
     if NumRelatives = 12 [ask n-of (3) Egyptians with [E_FamilyNumber = x][set age "old"] 
       ask n-of (4) Egyptians with [E_FamilyNumber = x] with [age !="old"][set age "adult"]
       ask n-of (5) Egyptians with [E_FamilyNumber = x] with [age !="old"] with [age != "adult"][set age "young"]]
     ask one-of Egyptians with [E_FamilyNumber = x] with [gender = 1] with [age != "old"][set status "Migrant" set years 0 move-to one-of IncomingAreas]
     set x x + 1] 
  
  create-Turkishes (Turkey_population)
  ask Turkishes [move-to one-of TurkeyBlock set shape "person" set color black set status "NonMigrant"] 
  
  set x 1
  repeat (Turkey_population / NumRelatives) [
     ask n-of (NumRelatives) Turkishes with [T_FamilyNumber = 0] [
       set T_FamilyNumber x create-familylinks-with other Turkishes with [T_FamilyNumber = [T_FamilyNumber] of myself]]
     ask n-of (NumRelatives / 2) Turkishes with [T_FamilyNumber = x][set gender 1]                                        
     if NumRelatives = 6 [ask n-of (1) Turkishes with [T_FamilyNumber = x][set age "old"] 
       ask n-of (2) Turkishes with [T_FamilyNumber = x] with [age !="old"][set age "adult"]
       ask n-of (3) Turkishes with [T_FamilyNumber = x] with [age !="old"] with [age != "adult"][set age "young"]]
     if NumRelatives = 9 [ask n-of (2) Turkishes with [T_FamilyNumber = x][set age "old"] 
       ask n-of (3) Turkishes with [T_FamilyNumber = x] with [age !="old"][set age "adult"]
       ask n-of (4) Turkishes with [T_FamilyNumber = x] with [age !="old"] with [age != "adult"][set age "young"]]
     if NumRelatives = 12 [ask n-of (3) Turkishes with [T_FamilyNumber = x][set age "old"] 
       ask n-of (4) Turkishes with [T_FamilyNumber = x] with [age !="old"][set age "adult"]
       ask n-of (5) Turkishes with [T_FamilyNumber = x] with [age !="old"] with [age != "adult"][set age "young"]]
     ask one-of Turkishes with [T_FamilyNumber = x] with [gender = 1] with [age != "old"][set status "Migrant" set years 0 move-to one-of IncomingAreas]
     set x x + 1]
   
   ask links [ifelse show-links? [set color black - 2] [hide-link]]       
    
end

to variable                          ; assign variables to agents and countries
  
  ask Moroccans [let r random-float 1                                                                                              ; assign skills to all agents according to probabilities setted in the interface
    ifelse r < Mp_no_edu [set skills 0] [ifelse r < (Mp_no_edu + Mp_edu_1) [set skills 1]     
      [ifelse r < (Mp_no_edu + Mp_edu_1 + Mp_edu_2) [set skills 2] 
        [ifelse r < (Mp_no_edu + Mp_edu_1 + Mp_edu_2 + Mp_edu_3) [set skills 3] [set skills 4]]]]]
  ask Egyptians [let r random-float 1 
    ifelse r < Ep_no_edu [set skills 0] [ifelse r < (Ep_no_edu + Ep_edu_1) [set skills 1] 
      [ifelse r < (Ep_no_edu + Ep_edu_1 + Ep_edu_2) [set skills 2] 
        [ifelse r < (Ep_no_edu + Ep_edu_1 + Ep_edu_2 + Ep_edu_3) [set skills 3] [set skills 4]]]]]
  ask Turkishes [let r random-float 1 
    ifelse r < Tp_no_edu [set skills 0] [ifelse r < (Tp_no_edu + Tp_edu_1) [set skills 1] 
      [ifelse r < (Tp_no_edu + Tp_edu_1 + Tp_edu_2) [set skills 2] 
        [ifelse r < (Tp_no_edu + Tp_edu_1 + Tp_edu_2 + Tp_edu_3) [set skills 3] [set skills 4]]]]]
  
  ask Moroccans [if random-normal M_value_mean M_value_deviation > 0 [set income random-normal M_value_mean M_value_deviation]]     ; assign income to all agents according to a Normal distribution with mean and standard deviation setted in the interface 
  ask Egyptians [if random-normal E_value_mean E_value_deviation > 0 [set income random-normal E_value_mean E_value_deviation]]                       
  ask Turkishes [if random-normal T_value_mean T_value_deviation > 0 [set income random-normal T_value_mean T_value_deviation]]
  
  ask turtles [ifelse skills = 1 [set SavingsAbility 0.02][ifelse skills = 2 [set SavingsAbility 0.04]
      [ifelse skills = 3 [set SavingsAbility 0.06][ifelse skills = 4 [set SavingsAbility 0.08][set SavingsAbility 0.10]]]]]         ; assign saving ability according to skills
  
  set M_gdp 50000 set E_gdp 100000 set T_gdp 150000  set Eu_gdp 450000 set MiddleEast_gdp 150000 set Asia_gdp 300000                ; assign gdp to countries
  
  if any? Moroccans-on EuropeBlock [ask Moroccans-on EuropeBlock [set dist 1 ask familylink-neighbors [set dist 1]]]                ; assign the distance between the family and the pioneer                                                                                        
  if any? Moroccans-on MiddleEastBlock [ask Moroccans-on MiddleEastBlock [set dist 3 ask familylink-neighbors [set dist 3]]]  
  if any? Moroccans-on AsiaBlock [ask Moroccans-on AsiaBlock [set dist 6 ask familylink-neighbors [set dist 6]]]  
    
  if any? Egyptians-on EuropeBlock [ask Egyptians-on EuropeBlock [set dist 3 ask familylink-neighbors [set dist 3]]]                                                                                          
  if any? Egyptians-on MiddleEastBlock [ask Egyptians-on MiddleEastBlock [set dist 1 ask familylink-neighbors [set dist 1]]]    
  if any? Egyptians-on AsiaBlock [ask Egyptians-on AsiaBlock [set dist 5 ask familylink-neighbors [set dist 5]]]  

  if any? Turkishes-on EuropeBlock [ask Turkishes-on EuropeBlock [set dist 2 ask familylink-neighbors [set dist 2]]]                                                                                      
  if any? Turkishes-on MiddleEastBlock [ask Turkishes-on MiddleEastBlock [set dist 2 ask familylink-neighbors [set dist 2]]]  
  if any? Turkishes-on AsiaBlock [ask Turkishes-on AsiaBlock [set dist 4 ask familylink-neighbors [set dist 4]]]  
  
end

to go
  
  if ticks = 25 [stop]   
  SetVariables
  Migration
  ComeBack         
  SetGlobals
  tick
  
end

    
to SetVariables                          ; assign to agents the variables that change every ticks  *non solo!!!  
  
  set M_gdp_t-1  M_gdp set E_gdp_t-1  E_gdp set T_gdp_t-1  T_gdp
  set Eu_gdp_t-1  Eu_gdp set MiddleEast_gdp_t-1  MiddleEast_gdp set Asia_gdp_t-1  Asia_gdp            ; at t = 1 set gdp_t-1 as gdp of t = 0  
  
  ifelse ticks < 1 [set r_M 0][set r_M r_M]                                                           ; at t = 0 set growth rate at 0
  ifelse ticks < 1 [set r_E 0][set r_E r_E] 
  ifelse ticks < 1 [set r_T 0][set r_T r_T]                                                            
  
  ask turtles [set InvestedRemittances_t-1 InvestedRemittances]   
  
  ask turtles-on IncomingAreas [set years (years + 1)]                                                ; increases years spent abroad every tick
  
  ask turtles-on MoroccoBlock [ifelse age = "young" [set wage 0]                                                                             ; assign wage to agents on OutcomingCountries
    [ifelse age = "adult" [set wage ((2000 * skills) + (M_gdp / 25))] [set wage (0.6 * ((2000 * skills) + (M_gdp / 25)))]]]                                                                                              
  ask turtles-on EgyptBlock [ifelse age = "young" [set wage 0] [ifelse age = "adult" [set wage ((2000 * skills) + (E_gdp / 25))] 
      [set wage (0.6 * ((2000 * skills) + (E_gdp / 25)))]]]
  ask turtles-on TurkeyBlock [ifelse age = "young" [set wage 0] [ifelse age = "adult" [set wage ((2000 * skills) + (T_gdp / 25))] 
      [set wage (0.6 * ((2000 * skills) + (T_gdp / 25)))]]]
  
  ask turtles-on EuropeBlock                                                                                                                  ; assign wage and level of integration to pioneers
  [if age = "young" [set wage ((3000 * skills) + (Eu_gdp / 25))] if age = "adult" [set wage ((3000 * skills) + (Eu_gdp / 25))]]    
  ask turtles-on MiddleEastBlock [if age = "young" [set wage ((3000 * skills) + (MiddleEast_gdp / 25))] if age = "adult" 
    [set wage ((3000 * skills) + (MiddleEast_gdp / 25))]]
  ask turtles-on AsiaBlock [if age = "young" [set wage ((3000 * skills) + (Asia_gdp / 25))] if age = "adult" 
    [set wage ((3000 * skills) + (Asia_gdp / 25))]] 
  
  ask turtles-on EuropeBlock [ifelse Eu_integration = "high" [set integration 0.9][ifelse Eu_integration = "medium" [set integration 0.8][set integration 0.7]]]    ; assign the level of integration according to the interface
  ask turtles-on MiddleEastBlock [ifelse MiddleEast_integration = "high" [set integration 0.9][ifelse MiddleEast_integration = "medium" [set integration 0.8][set integration 0.7]]]
  ask turtles-on AsiaBlock [ifelse Asia_integration = "high" [set integration 0.9][ifelse Asia_integration = "medium" [set integration 0.8][set integration 0.7]]]
  
  ask turtles-on IncomingAreas [set SavingsNumRelatives ((count link-neighbors with [status = "NonMigrant"]) * 0.005)]                  ; assign to pioneers a parameter for the level of savings according to the numbers of relatives at home
  
  ask turtles-on OutcomingCountries [ifelse (count link-neighbors with [status = "NonMigrant"]) = 2 [set SavingsNumRelatives 0.02]      ; assign a parameter for the level of savings according to the numbers of relatives abroad
    [ifelse (count link-neighbors with [status = "NonMigrant"]) = 3 [set SavingsNumRelatives 0.02]
      [ifelse (count link-neighbors with [status = "NonMigrant"]) = 4 [set SavingsNumRelatives 0.04] 
        [ifelse (count link-neighbors with [status = "NonMigrant"]) = 5 [set SavingsNumRelatives 0.06] 
          [ifelse (count link-neighbors with [status = "NonMigrant"]) = 6 [set SavingsNumRelatives 0.04]
           [ifelse (count link-neighbors with [status = "NonMigrant"]) = 7 [set SavingsNumRelatives 0.02] 
            [ifelse (count link-neighbors with [status = "NonMigrant"]) = 8 [set SavingsNumRelatives 0.02][set SavingsNumRelatives 0]]]]]]]]

  ask turtles with [status = "Migrant"]  
  [set remittances ((wage * (SavingsAbility + SavingsNumRelatives + 0.1)) / (count link-neighbors with [status = "NonMigrant"]))]                                ; assign remittances to pioneer
  
  ask turtles with [status = "NonMigrant"]
  [set RemittancesReceived (sum [remittances] of link-neighbors with [status = "Migrant"])]                                                                      ; assign remittances received to relatives

  ask turtles with [status = "NonMigrant"] with [age != "young"] [let r ((0 - 0.035) + random-float 0.7)                                                                  ; assign invested remittances  
    if age = "adult" [set InvestedRemittances ((InvestedRemittances * (1 + r)) + (RemittancesReceived * (SavingsAbility + SavingsNumRelatives)))]
    if age = "old" [set InvestedRemittances ((InvestedRemittances * (1 + r)) + (RemittancesReceived * ((SavingsAbility + SavingsNumRelatives) * 1.05)))]] 
  
  ask turtles with [status = "NonMigrant"] with [age != "young"] 
  [if age = "adult" [set ConsumedRemittances RemittancesReceived - RemittancesReceived * (SavingsAbility + SavingsNumRelatives)] 
    if age = "old" [ set ConsumedRemittances RemittancesReceived - (RemittancesReceived * (SavingsAbility + SavingsNumRelatives)) * 1.05]]                                                   
   
  ask turtles-on OutcomingCountries [if any? link-neighbors with [status = "Migrant"]                                                    ; assign to agents on Outcoming countries the potential wage
    [set PotentialWage (mean [wage] of link-neighbors with [status = "Migrant"])] ask link-neighbors with [status = "Migrant"] [set MyFamilyPW [PotentialWage] of myself]]
  
  ask turtles-on IncomingAreas [set PotentialWage (mean [wage] of familylink-neighbors with [status = "NonMigrant"])                     ; assign to pioneers the potential wage and the potential wealth
                                set PotentialWealth (mean [InvestedRemittances] of familylink-neighbors with [status = "NonMigrant"])]

end  
  
  
to Migration                          ; new migration from Outcoming countries   

  ask Moroccans with [status = "NonMigrant"] [let stability 0 if M_politics = "stable" [set stability 1] set MySituation1 
    ((dist / max [dist] of turtles-on MoroccoBlock)  + (wage / max [wage] of turtles-on MoroccoBlock) + 0.5 * (income / max [income] of turtles-on MoroccoBlock)         
      + 0.001 * (count link-neighbors with [status = "NonMigrant"] / (NumRelatives - 2)) + 0.3 * (InvestedRemittances / max [InvestedRemittances] of turtles-on MoroccoBlock) 
       + 100 * r_M - 0.1 * gender - (skills / 4) + 0.1 * stability)]  
  ask Egyptians with [status = "NonMigrant"] [let stability 0 if E_politics = "stable" [set stability 1] set MySituation1
    ((dist / max [dist] of turtles-on EgyptBlock)  + (wage / max [wage] of turtles-on EgyptBlock) + 0.5 * (income / max [income] of turtles-on EgyptBlock) 
      + 0.001 * (count link-neighbors with [status = "NonMigrant"] / (NumRelatives - 2)) + 0.3 * (InvestedRemittances / max [InvestedRemittances] of turtles-on EgyptBlock)
       + 100 * r_E - 0.1 * gender - (skills / 4) + 0.1 * stability)]
  ask Turkishes with [status = "NonMigrant"] [let stability 0 if T_politics = "stable" [set stability 1] set MySituation1
    ((dist / max [dist] of turtles-on TurkeyBlock) + (wage / max [wage] of turtles-on TurkeyBlock) + 0.5 * (income / max [income] of turtles-on TurkeyBlock)
      + 0.001 * (count link-neighbors with [status = "NonMigrant"] / (NumRelatives - 2)) + 0.3 * (InvestedRemittances / max [InvestedRemittances] of turtles-on TurkeyBlock)
       + 100 * r_T - 0.1 * gender - (skills / 4) + 0.1 * stability)]   
  
  ask EuropeBlock 
    [if any? turtles-here [ask one-of turtles-here                                  ;chiedo ad un solo agente per patch (cioè ad uno solo per famiglia)
        [if any? familylink-neighbors with [status = "NonMigrant"] with [age != "old"] [ask min-one-of familylink-neighbors with [status = "NonMigrant"] with [age != "old"] [MySituation1] 
            [let restrictions 0 if Eu_barriers = "high" [set restrictions 1] set MyPotentialSituation1 (100 * r_Eu + 0.5 * (PotentialWage / max [MyFamilyPW] of turtles-on EuropeBlock) - 0.1 * restrictions) 
              if MySituation1 < MyPotentialSituation1 [move-to myself    
           set status "Migrant" set RemittancesReceived 0 set MySituation1 0 set MyPotentialSituation1 0 set years 0]]]]]]
                                              ; prendono tutte le variabili che aveva preso il pioniere al tempo t=0     
  ask MiddleEastBlock  
    [if any? turtles-here [ask one-of turtles-here                                  ;chiedo ad un solo agente per patch (cioè ad uno solo per famiglia)
        [if any? familylink-neighbors with [status = "NonMigrant"] with [age != "old"] [ask min-one-of familylink-neighbors with [status = "NonMigrant"] with [age != "old"] [MySituation1] 
            [let restrictions 0 if MiddleEast_barriers = "high" [set restrictions 1] set MyPotentialSituation1 (100 * r_MiddleEast + 0.5 * (PotentialWage / max [MyFamilyPW] of turtles-on MiddleEastBlock) - 0.1 * restrictions) 
              if MySituation1 < MyPotentialSituation1 [move-to myself    
           set status "Migrant" set RemittancesReceived 0 set MySituation1 0 set MyPotentialSituation1 0 set years 0]]]]]]
  
  ask AsiaBlock 
    [if any? turtles-here [ask one-of turtles-here                                  ;chiedo ad un solo agente per patch (cioè ad uno solo per famiglia)
        [if any? familylink-neighbors with [status = "NonMigrant"] with [age != "old"] [ask min-one-of familylink-neighbors with [status = "NonMigrant"] with [age != "old"] [MySituation1] 
            [let restrictions 0 if Asia_barriers = "high" [set restrictions 1] set MyPotentialSituation1 (100 * r_Asia + 0.5 * (PotentialWage / max [MyFamilyPW] of turtles-on AsiaBlock) - 0.1 * restrictions) 
              if MySituation1 < MyPotentialSituation1 [move-to myself    
           set status "Migrant" set RemittancesReceived 0 set MySituation1 0 set MyPotentialSituation1 0 set years 0]]]]]]
   
  ask IncomingAreas [if any? turtles-here [ask one-of turtles-here [set size 1 + (0.1 * (count turtles-here - 1))]]] 
       
end


to ComeBack                          ; migrants go back to the original country   
  
  ask EuropeBlock   
  [if any? Moroccans-here with [years > 8] 
    [ask Moroccans-here with [years > 8] 
      [let stability 0 if M_politics = "stable" [set stability 1]
         set MySituation2 (100 * r_M + (integration / 0.9) + 0.001 * ((count link-neighbors with [status = "Migrant"]) / (NumRelatives - 3))
           + (wage / max [wage] of Moroccans-on EuropeBlock) - (dist / max [dist] of Moroccans-on EuropeBlock) - 0.1 * gender ) 
         set MyPotentialSituation2  (0.1 * stability + 0.5 * (PotentialWage / max [PotentialWage] of Moroccans-on EuropeBlock) 
           + 0.3 * (PotentialWealth / max [PotentialWealth] of Moroccans-on EuropeBlock) + 100 * r_Eu) ] 
      ask min-one-of Moroccans-here with [years > 8] [MySituation2] [if MySituation2 < MyPotentialSituation2  
        [move-to one-of MoroccoBlock set status "ReturnNonMigrant" set remittances 0 set MySituation2 0 set MyPotentialSituation2  0 ]]] 
    
  if any? Egyptians-here with [years > 8] 
    [ask Egyptians-here with [years > 8]
      [let stability 0 if E_politics = "stable" [set stability 1] 
        set MySituation2 (100 * r_E +  (integration / 0.9) + 0.001 * ((count link-neighbors with [status = "Migrant"]) / (NumRelatives - 3)) 
          + (wage / max [wage] of Egyptians-on EuropeBlock) - (dist / max [dist] of Egyptians-on EuropeBlock) - 0.1 * gender ) 
        set MyPotentialSituation2  (0.1 * stability + 0.5 * (PotentialWage / max [PotentialWage] of Egyptians-on EuropeBlock) 
          + 0.3 * (PotentialWealth / max [PotentialWealth] of Egyptians-on EuropeBlock) + 100 * r_Eu) ] 
     ask min-one-of Egyptians-here with [years > 8] [MySituation2] [if MySituation2 < MyPotentialSituation2  
       [move-to one-of EgyptBlock set status "ReturnNonMigrant" set remittances 0 set MySituation2 0 set MyPotentialSituation2  0 ]]]  
  
  if any? Turkishes-here with [years > 8] 
    [ask Turkishes-here with [years > 8]
      [let stability 0 if T_politics = "stable" [set stability 1] 
        set MySituation2 (100 * r_T + 1 * (integration / 0.9) + 0.001 * ((count link-neighbors with [status = "Migrant"]) / (NumRelatives - 3))
           + (wage / max [wage] of Turkishes-on EuropeBlock) - (dist / max [dist] of Turkishes-on EuropeBlock) - 0.1 * gender ) 
        set MyPotentialSituation2  (0.1 * stability + 0.5 * (PotentialWage / max [PotentialWage] of Turkishes-on EuropeBlock) 
          + 0.3 * (PotentialWealth / max [PotentialWealth] of Turkishes-on EuropeBlock) + 100 * r_Eu) ] 
     ask min-one-of Turkishes-here with [years > 8] [MySituation2] [if MySituation2 < MyPotentialSituation2  
       [move-to one-of TurkeyBlock set status "ReturnNonMigrant" set remittances 0 set MySituation2 0 set MyPotentialSituation2  0 ]]]]
  
  
  ask MiddleEastBlock
  [if any? Moroccans-here with [years > 8]
   [ask Moroccans-here with [years > 8] 
      [let stability 0 if M_politics = "stable" [set stability 1] 
        set MySituation2 (100 * r_M + 1 * (integration / 0.9) + 0.001 * ((count link-neighbors with [status = "Migrant"]) / (NumRelatives - 3)) 
          + (wage / max [wage] of Moroccans-on MiddleEastBlock) - (dist / max [dist] of Moroccans-on MiddleEastBlock) - 0.1 * gender ) 
        set MyPotentialSituation2  (0.1 * stability + 0.5 *(PotentialWage / max [PotentialWage] of Moroccans-on MiddleEastBlock) 
          + 0.3 * (PotentialWealth / max [PotentialWealth] of Moroccans-on MiddleEastBlock) + 100 * r_MiddleEast) ] 
     ask min-one-of Moroccans-here with [years > 8] [MySituation2] [if MySituation2 < MyPotentialSituation2  
       [move-to one-of MoroccoBlock set status "ReturnNonMigrant" set remittances 0 set MySituation2 0 set MyPotentialSituation2  0 ]]] 
    
  if any? Egyptians-here with [years > 8] 
    [ask Egyptians-here with [years > 8]
      [let stability 0 if E_politics = "stable" [set stability 1] 
        set MySituation2 (100 * r_E + 1 * (integration / 0.9) + 0.001 * ((count link-neighbors with [status = "Migrant"]) / (NumRelatives - 3)) 
          + (wage / max [wage] of Egyptians-on MiddleEastBlock) - (dist / max [dist] of Egyptians-on MiddleEastBlock) - 0.1 * gender ) 
        set MyPotentialSituation2  (0.1 * stability + 0.5 * (PotentialWage / max [PotentialWage] of Egyptians-on MiddleEastBlock) 
          + 0.3 * (PotentialWealth / max [PotentialWealth] of Egyptians-on MiddleEastBlock) + 100 * r_MiddleEast) ] 
     ask min-one-of Egyptians-here with [years > 8] [MySituation2] [if MySituation2 < MyPotentialSituation2  
       [move-to one-of EgyptBlock set status "ReturnNonMigrant" set remittances 0 set MySituation2 0 set MyPotentialSituation2  0 ]]]  
  
  if any? Turkishes-here with [years > 8] 
    [ask Turkishes-here with [years > 8]
      [let stability 0 if T_politics = "stable" [set stability 1] 
        set MySituation2 (100 * r_T + 1 * (integration / 0.9) + 0.001 * ((count link-neighbors with [status = "Migrant"]) / (NumRelatives - 3)) 
          + (wage / max [wage] of Turkishes-on MiddleEastBlock) - (dist / max [dist] of Turkishes-on MiddleEastBlock) - gender ) 
        set MyPotentialSituation2  (0.1 * stability + 0.5 * (PotentialWage / max [PotentialWage] of Turkishes-on MiddleEastBlock) 
          + 0.3 * (PotentialWealth / max [PotentialWealth] of Turkishes-on MiddleEastBlock) + 100 * r_MiddleEast) ] 
     ask min-one-of Turkishes-here with [years > 8] [MySituation2] [if MySituation2 < MyPotentialSituation2  
       [move-to one-of TurkeyBlock set status "ReturnNonMigrant" set remittances 0 set MySituation2 0 set MyPotentialSituation2  0 ]]]]
   
  ask AsiaBlock 
  [if any? Moroccans-here with [years > 8] 
   [ask Moroccans-here with [years > 8] 
      [let stability 0 if M_politics = "stable" [set stability 1] 
        set MySituation2 (100 * r_M + 1 * (integration / 0.9) + 0.001 * ((count link-neighbors with [status = "Migrant"]) / (NumRelatives - 3)) 
          + (wage / max [wage] of Moroccans-on AsiaBlock) - (dist / max [dist] of Moroccans-on AsiaBlock) - 0.1 * gender ) 
        set MyPotentialSituation2  (0.1 * stability + 0.5 * (PotentialWage / max [PotentialWage] of Moroccans-on AsiaBlock) 
          + 0.3 * (PotentialWealth / max [PotentialWealth] of Moroccans-on AsiaBlock) + 100 * r_Asia) ] 
     ask min-one-of Moroccans-here with [years > 8] [MySituation2] [if MySituation2 < MyPotentialSituation2  
       [move-to one-of MoroccoBlock set status "ReturnNonMigrant" set MySituation2 0 set MyPotentialSituation2  0 ]]] 
    
  if any? Egyptians-here with [years > 8] 
    [ask Egyptians-here with [years > 8]
      [let stability 0 if E_politics = "stable" [set stability 1] 
        set MySituation2 (100 * r_E + 1.1 * (integration / 0.9) + 0.001 * ((count link-neighbors with [status = "Migrant"]) / (NumRelatives - 3)) 
          + (wage / max [wage] of Egyptians-on AsiaBlock) - (dist / max [dist] of Egyptians-on AsiaBlock) - 0.1 * gender ) 
        set MyPotentialSituation2  (0.1 * stability + 0.5 * (PotentialWage / max [PotentialWage] of Egyptians-on AsiaBlock) 
          + 0.3 * (PotentialWealth / max [PotentialWealth] of Egyptians-on AsiaBlock) + 100 * r_Asia) ] 
     ask min-one-of Egyptians-here with [years > 8] [MySituation2] [if MySituation2 < MyPotentialSituation2  
       [move-to one-of EgyptBlock set status "ReturnNonMigrant" set remittances 0 set MySituation2 0 set MyPotentialSituation2  0 ]]]  
  
  if any? Turkishes-here with [years > 8] 
    [ask Turkishes-here with [years > 8]
      [let stability 0 if T_politics = "stable" [set stability 1] 
        set MySituation2 (100 * r_T + 1 * (integration / 0.9) + 0.01 * ((count link-neighbors with [status = "Migrant"]) / (NumRelatives - 3)) 
          + (wage / max [wage] of Turkishes-on AsiaBlock) - (dist / max [dist] of Turkishes-on AsiaBlock) - 0.1 * gender ) 
        set MyPotentialSituation2  (0.1 * stability + 0.5 * (PotentialWage / max [PotentialWage] of Turkishes-on AsiaBlock) 
          + 0.3 * (PotentialWealth / max [PotentialWealth] of Turkishes-on AsiaBlock) + 100 * r_Asia) ] 
     ask min-one-of Turkishes-here with [years > 8] [MySituation2] [if MySituation2 < MyPotentialSituation2  
       [move-to one-of TurkeyBlock set status "ReturnNonMigrant" set remittances 0 set MySituation2 0 set MyPotentialSituation2  0 ]]]]
    
end


to SetGlobals                          ; set variables at the end of the cycle
  
  set M_RemittancesReceived M_RemittancesReceived + sum [RemittancesReceived] of turtles-on MoroccoBlock              ; sum remittances received by each country                
  set E_RemittancesReceived E_RemittancesReceived + sum [RemittancesReceived] of turtles-on EgyptBlock
  set T_RemittancesReceived T_RemittancesReceived + sum [RemittancesReceived] of turtles-on TurkeyBlock
  
  set M_ConsumedRemittances M_ConsumedRemittances + sum [ConsumedRemittances] of turtles-on MoroccoBlock
  set E_ConsumedRemittances E_ConsumedRemittances + sum [ConsumedRemittances] of turtles-on EgyptBlock
  set T_ConsumedRemittances T_ConsumedRemittances + sum [ConsumedRemittances] of turtles-on TurkeyBlock
  
  set M_gdp (M_gdp + ((M_ConsumedRemittances + sum [InvestedRemittances] of turtles-on MoroccoBlock - sum [InvestedRemittances_t-1] of turtles-on MoroccoBlock)* 0.0001))  
  set E_gdp (E_gdp + ((E_ConsumedRemittances + sum [InvestedRemittances] of turtles-on EgyptBlock - sum [InvestedRemittances_t-1] of turtles-on EgyptBlock)* 0.0001))                                                                  ; sum the total remittances received to the gdp of the Outcoming country
  set T_gdp (T_gdp + ((T_ConsumedRemittances + sum [InvestedRemittances] of turtles-on TurkeyBlock - sum [InvestedRemittances_t-1] of turtles-on TurkeyBlock)* 0.0001))    
   
  set Eu_gdp (Eu_gdp + 0.0001 * sum [wage] of turtles-on EuropeBlock )                                                                             ; sum total wages - remittances to the gdp of the Incoming countries
  set MiddleEast_gdp (MiddleEast_gdp + 0.0001 * sum [wage] of turtles-on MiddleEastBlock)
  set Asia_gdp (Asia_gdp + 0.0001 * sum [wage] of turtles-on AsiaBlock)
  
  
  set r_M ((M_gdp / M_gdp_t-1) - 1)                                                                                   ; set the growth rate
  set r_E ((E_gdp / E_gdp_t-1) - 1)
  set r_T ((T_gdp / T_gdp_t-1) - 1)
  
  set r_Eu  (( Eu_gdp - Eu_gdp_t-1) / Eu_gdp_t-1)                                                             
  set r_MiddleEast  (( MiddleEast_gdp - MiddleEast_gdp_t-1) / MiddleEast_gdp_t-1)
  set r_Asia  (( Asia_gdp - Asia_gdp_t-1) / Asia_gdp_t-1)
  
end