Serena Currone Enrico Mulè

Simulation models for economics

Project work on

"Consumption work leisure decisions: phase 1 simulation."




powered by NetLogo

view/download model file: phase1simulation.nlogo

WHAT IS IT?

This section could give a general understanding of what the model is trying to show or explain.


HOW IT WORKS

This section could explain what rules the agents use to create the overall behavior of the model.


HOW TO USE IT

This section could explain how to use the model, including a description of each of the items in the interface tab.


THINGS TO NOTICE

This section could give some ideas of things for the user to notice while running the model.


THINGS TO TRY

This section could give some ideas of things for the user to try to do (move sliders, switches, etc.) with the model.


EXTENDING THE MODEL

This section could give some ideas of things to add or change in the procedures tab to make the model more complicated, detailed, accurate, etc.


NETLOGO FEATURES

This section could point out any especially interesting or unusual features of NetLogo that the model makes use of, particularly in the Procedures tab. It might also point out places where workarounds were needed because of missing features.


RELATED MODELS

This section could give the names of models in the NetLogo Models Library or elsewhere which are of related interest.


CREDITS AND REFERENCES

This section could contain a reference to the model's URL on the web if it has one, as well as any other necessary credits or references.


PROCEDURES

breed [frms frm]                                                                                                                     
breed [wrkers wrker]                                                                                                                                                                                                                               
globals [NomWage PriceLvl RealWage deaths price]
wrkers-own [wage ReservSalary FirmNearw NumberOfSellers wealth work? buy? PiecesBought WhereIWork WhereIBuy LifePoints InitWealth MyFirmProduces]         ;; each variable that ends with "?" is a binary varible (can be only 0 or 1, 1 if the condition is satisfied otherwise 0).   
frms-own [NumWorkers Production produce? PiecesSold PiecesSoldNow  buyers stocks] 


to setup                                                                                                                                                  ;; button.                                        
  clear-all
  create-world
end
   
                                                                                                                                                       
to create-world                                                                                                                       
  create-wrkers workers                                                                                                                                    ;; slider.                                                                                                           
  create-frms firms                                                                                                                                        ;; slider.
  ask wrkers [set shape "person"
              setxy random-xcor random-ycor                                                                                                                ;; reporter command.
              set color red 
              set InitWealth initial-wealth                                                                                                                ;; each worker owns some money before he starts searching for a job. We create a slider: defines global variables, allowing to change its value without changing its code.
              set wealth InitWealth
              set Lifepoints initial-lifepoints                                                                                                            ;; each worker owns some lifepoints before he starts searching for job. With a slider we can choose the initial level of lifepoints of each worker.
              set size 1.3
              set ReservSalary random 30                                                                                                                   ;; in this phase we endow workers with a reservation salary.
              if ReservSalary < 5 [set ReservSalary 5 ]]                                                                                                                       
  ask frms [set shape "factory"
            setxy random-xcor random-ycor  
            set color white   
            set size 1.8
            if ycor >= 28 [set NomWage NomWageNORTH]                                                                                                       ;; in this phase we differenciate the nominal wage fixed by firms. We create three groups of firms: North, Center and South with different values of nominal wage (that can be changed arbitrarily during the simulation, thanks to the presence of the correspondent sliders). 
            if ycor < 28 [if ycor >= 14 [set NomWage NomWageCENTER]]                                                                                       ;; we assume that firms offer high nominal wage if they are placed in the North of our world (since in the North labour force is more productive), low nominal wage if they are placed in the South and "intermediate" nominal wage if they are placed in the Center. 
            if ycor < 14 [set NomWage NomWageSOUTH]]
  set price 10                                                                                                                                             ;; price is still fixed  
                                                                                                                                                                                                                                                                                                                                                                                                                           ;; then we end up with a unique level of the real wage.
end


to go                                                                                                                                                      ;; button.                                                                                                                    
  ifelse ticks < 1[search-for-job]                                                                                                                         ;; just to allow the production to start, then the world to operationally exist. No consumption decision is taken into account here.                                                                                                                           
  [ifelse ticks < 2 [produce]                                                                                                                              ;; to define how the production behaves.
  [search-for-job-goods                                                                                                                                    ;; here we take into account both contemporaneous work leisure decision and consumption decision.
  do-plots]]                                                                                                                                               ;; to have a graphic description of what happens in our world.
end

to go_forever                                                                                                                                              ;; this is practically the same as the previous "go" procedure; the only difference is that this one will run forever.
   ifelse ticks < 1[search-for-job]
    [ifelse ticks < 2 [produce]   
    [search-for-job-goods
     do-plots]]
end

to search-for-job
ask wrkers [set FirmNearw count frms in-radius searching-radiusW                                                                                           ;; in this procedure we don't take into account the complication of the different nominal wages in workers' decisions since it's just a procedure that allows the production to start, then the world to operationally exist. Therefore each worker decides where to work on the basis of the real wage, that in this phase is perfectly known (no informational asimmetry), and of how far he is from a firm: being here the real wage unique for all firms, agents choose to work in firms that are nearer to them.                                                                                                                                        
            set WhereIWork  one-of frms in-radius searching-radiusW                                                                                        ;; set a radius that simulates workers' vision capacity: each worker chooses randomly to work in one of the firms in the radius (i.e. "FirmNearw"), that are assumed to be the nearest one. This corresponds to "WhereIWork".
            ifelse FirmNearw > 0                                                                                                                           ;; if there's at least one firm in the radius, worker starts to work turning his color into green and then the firm starts to produce ("MyFirmProduces").
             [set wage NomWage
              set color green                       
              move-to WhereIWork                                                                                                              
              set MyFirmProduces WhereIWork ]                                                                                                      
           [right random 360 forward 1 set LifePoints LifePoints - 1]]                                                                                     ;; otherwise, he picks a random whole number from 0 to 359 and turns right this number of degrees. Then he moves forward one step: each movement causes the loss of one lifepoint. (Note: here we've a reporter command).
tick-advance 1
end


to produce
  ask frms [set NumWorkers count wrkers with [pxcor = [pxcor] of myself and pycor = [pycor] of myself]                                                     ;; to know how many workers are employed in each firm.                                                                                                                   
            if NumWorkers > 0 [set production 6 * NumWorkers                                                                                               ;; if there is at least one worker employed, the firm starts producing, "produce? 1", (according to a well-behaved production function of the (arbitrarily chosen) form: 6 multiplied by the number of inputs, that is the number of workers) and turns its color into violet. 
                               set produce? 1  
                               set color violet ]                                                                                    
            if production > 0 [set price 10
                               set PriceLvl price]]                                                                                                        ;; each firm that produces sets its sell price, that in this phase of the model is assumed to be equal for all firms (it's then possible to speak about price level).                                                                                                                
tick-advance 1
end


to search-for-job-goods                                                                                                                                    ;; agents are now considered both as workers and as consumers.
ask wrkers [set FirmNearw count frms in-radius searching-radiusW with [NomWage >= [ReservSalary]of myself]
            set WhereIWork  one-of frms in-radius searching-radiusW with [NomWage >= [ReservSalary]of myself]                                              ;; in this procedure we take into account the complication of different nominal wages: workers chooses randomly in the radius one of the firms that offer a nominal wage greater or equal to their reservation salary.                                                                                                 
            set NumberOfSellers count frms with [produce? = 1] in-radius searching-radiusC                                                                 ;; nothing changes on consumption-choices side since only nominal wage changes in this phase. Each consumer is endowed with another radius (smaller than the worker's one) and can see how many firms producing goods there are in that radius: all these minimizes the research costs that in this phase of the model, in which all firms sell the same good at the same price, is the only determinant of the choice of the firm where to buy.
            ifelse FirmNearw > 0 [ifelse NumberOfSellers > 0 [  set color green                                                                            ;; if there's at least one firm in the radius and it produces, then worker starts to work turning its color into green. By working, he perceives the nominal wage increasing his wealth.
                                                                ifelse ticks < 1 [set wealth (InitWealth + wage)] [set wealth (wealth + wage)]  
                                                                set work? 1 
                                                                move-to WhereIWork
                                                                set wage [NomWage] of WhereIWork
                                                             if wealth >= price [set wealth (wealth - price)                                               ;; contemporaneously the agent chooses randomly one of the firms that are in the smaller consumer-searching-radius (again, there has to be at least one firm in the radius), since we assume that they minimize the research costs.
                                                                                 set WhereIBuy one-of frms in-radius searching-radiusC                     ;; if his wealth in greater or equal than the price of the good then the agent purchases it, increasing his siza .
                                                                                 set buy? 1 
                                                                                 set size 2.1
                                                                                 set PiecesBought PiecesBought + 1]]                                       ;; we assume that each agent can purchase just one unit of good per tick.
                                    [right random 360 forward 1                                                                                            ;; if there isn't any firm in the consumer-searching-radius, then the agent turns his head randomly and go ahead of one step. This causes the loss of one lifepoint and the decrease of the wealth of an amount equal to the research costs supported (that are increased).
                                     set color red
                                     set wealth (wealth - ResearchCosts)
                                     set LifePoints LifePoints - 1]] 
                                                                             [right random 360 forward 1                                                   ;; if there isn't any firm in the worker-searching-radius, then the agent turns its head randomly and go ahead of one step. This causes the loss of one lifepoint and the decrease of the wealth of an amount equal to the travel costs supported (that are increased).
                                                                              set color red
                                                                              set wealth (wealth - TravelCosts) 
                                                                              set LifePoints LifePoints - 1
                                                                              set ReservSalary (ReservSalary - 1)]
                                                                                                                                      
            ifelse unemployment_benefit [if work? = 0 [set wage (0.5 * NomWage)
                                                       ifelse ticks < 1 [set wealth (InitWealth + wage)] [set wealth (wealth + wage)] 
                                                       if LifePoints < -5 [die]]]
                                        [if LifePoints < 0 [die]]]  
                                                                                                                                                           ;; if lifepoints decrease till becoming lower than one, the agent dies.                                                                                                
ask frms [set NumWorkers count wrkers with [pxcor = [pxcor] of myself and pycor = [pycor] of myself]                                                       ;; to know how many workers are employed in each firm.                                                                                                                   
          if NumWorkers > 0 [set production 6 * NumWorkers                                                                                                 ;; if there is at least one worker employed, the firm starts producing, "produce? 1", (according to a well-behaved production function of the (arbitrarily chosen) form: 6 multiplied by the number of inputs, that is the number of workers) and turns its color into violet. 
                               set produce? 1  
                               set color violet ]                                                                                    
          if production > 0 [set price 10
                             set price PriceLvl]]

ask frms [set buyers count wrkers with [ WhereIBuy = myself ]                                                                                              ;; to quantify the number of units of good sold by each firm.
           set PiecesSoldNow buyers
           set PiecesSold (PiecesSold + buyers)
           ifelse benefit_for_firms [if ticks > 12 [if PiecesSold < 1 [die]]]                                                                              ;; if the government buys goods to the firms that don't sell to the pubblic for 12 ticks, then a firm stops its business and gets out of the market only if it keeps on not selling to the public after 12 ticks.
                                           [if PiecesSold < 1 [die]]                                                                                       ;; otherwise, a firm that doesn't sell any good to the public stops its business and gets out of the market immediately.
          set stocks (stocks + production - PiecesSoldNow)                                                                                                 ;; there's a warehouse for each firm.
          if buyers > 2 [set size 3]                                                                                                                       ;; the more a firm sells, the bigger it becomes.                                                                                            
          if buyers > 4 [set size 4]]      

tick-advance 1                                                                                                                                       
ask frms [set label  count wrkers with [pxcor = [pxcor] of myself and pycor = [pycor] of myself]]                                                          ;; to have a label associated to each firm telling us how many workers are enroled.
show max-one-of frms [PiecesSold]                                                                                                                          ;; to know which is the firm that sell more.                                                                                                                                                                                                                                                                                                               
end




to do-plots
  set-current-plot "unemployment"                                                                                                                          ;; to have a graphical representation of how unemployment behaves along time.                                                                                                   
  set-current-plot-pen "unemployment"
  plot count wrkers with [work? = 0 ]
  set-current-plot "employment"                                                                                                                            ;; to have a graphical representation of how employment behaves along time.
  set-current-plot-pen "employment"                                                                                                                        ;; these are two faces of the same coin: they have to be coherent one with the other.
  plot count wrkers with [work? = 1]

end