Serena Currone Enrico Mulè

Simulation models for economics

Project work on

"Consumption work leisure decisions: phase 0 simulation."




powered by NetLogo

view/download model file: phase0simulation.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 price]
wrkers-own [wage FirmNearw NumberOfSellers wealth work? buy? PiecesBought WhereIWork WhereIBuy LifePoints InitWealth MyFirmProduces]              
frms-own [NumWorkers Production produce? PiecesSold PiecesSoldNow buyers stocks]                                                                   ;; each variable that ends with "?" is a binary varible (can be only 0 or 1, 1 if the condition is satisfied otherwise 0).


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
              set size 1.3]                                                                                                                         ;; 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.              
  ask frms [set shape "factory"
            setxy random-xcor random-ycor  
            set color white   
            set size 1.8
            set NomWage 20]
  set price 10
  set PriceLvl price                                                                                                                                ;; in this phase all firms fix the same nominal wage and price (it's then possible to speak about price level).                                                                                                                                      ;; in this phase price level is fixed and common to all firms (we give to it a random value). We can therefore speak about "price level".     l                                                                                                                    ;; then we end up with a unique level of the real wage.
end


to go                                                                                                                                               ;; button.                                                                                                                    
  search-for-job                                                                                                                                    ;; just to allow the production to start, then the world to operationally exist. No consumption decision is taken into account here.                                                                                                                           
  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.
  search-for-job
  produce
  search-for-job-goods
  do-plots
end  


to search-for-job
ask wrkers [set FirmNearw count frms in-radius searching-radiusW                                                                                     ;; 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                                                                                                           ;; 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). 
             LifePoints LifePoints - 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 ]]                                                                                    
                                                                                                                                                                                                                            
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 
            set WhereIWork  one-of frms in-radius searching-radiusW                                                                                  ;; again, workers search for job as in the "search-for-job procedure". Here travel costs are taken into account: being it in this phase of the model the only determinant of the choice of the firm where to work, we can assume that all the firms in the radius minimize this cost. Then each worker chooses randomly one of these firms (implicit assumption that agents aren't perfectly rational).                                                   
            set NumberOfSellers count frms with [produce? = 1] in-radius searching-radiusC                                                           ;; 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 wage NomWage
                                                               set color green                                                                       ;; if there's at least one firm in the radius and it produces, then worker starts to work turning his color into green. By working, he perceives the nominal wage increasing his wealth.
                                                                ifelse ticks < 1 [set wealth (InitWealth + NomWage)] [set wealth (wealth + NomWage)]  
                                                                set work? 1 
                                                                move-to WhereIWork
                                                             if wealth >= price [set wealth (wealth - 10)                                            ;; 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, becoming bigger.
                                                                                 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]
                                                                                                                                      
            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 < 1 [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 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_firm [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]]         

                                                                                                                                       
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.                                                                                         
tick-advance 1                                                                                                                                                                                                                      
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