Serena Currone Enrico Mulè

Simulation models for economics

Project work on

"Consumption work leisure decisions: phase 2 and 3 simulation."




powered by NetLogo

view/download model file: phase2and3simulation.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 [PriceLvl deaths MediumPrice Mark-Up SumPrice*Prod SumProd] 
wrkers-own [wage FirmNearw NumberOfSellers wealth work? buy? PiecesBought WhereIWork WhereIBuy LifePoints InitWealth MyFirmProduces ReservSalary ReservPrice IfICanBuy SellingPrice]                      ;; 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 produce? PiecesSold buyers stocks costs KNORTH KCENTER KSOUTH UnitaryCost PiecesSoldNow N price*prod price production NomWage QualityDiscountFactor RealWage]  


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
              set wealth InitWealth                                                                                                                                                                       ;; 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 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                                                                                                                                                                  ;; we endow workers with a reservation salary.
              if ReservSalary < 5 [set ReservSalary 5 ]                                                                                                          
              set ReservPrice random 40
              if ReservPrice < 5 [set ReservPrice 5 ]]                                                                                                                                                    ;; we endow consumers with a reservation price.                                                                                                                 
  ask frms [set shape "factory"
            setxy random-xcor random-ycor  
            set color white   
            set size 1.8
            if ycor >= 28 [set NomWage NomWageNORTH]                                                                                                                                                      ;; we differentiate 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]                                                                                                                                                       ;; in this phase we allow firms for the possibility of having different technologies (this's coherent with the fact that now we aren't anymore in a perfectly competitive environment). "K" is a random constant which represent the technology: the higher it is, the better is the technology involved in the production. In particular we assume it to be high in the North of our world, lower in the South and at an intemediate level in the Center. 
            set KNORTH random 25 if KNORTH < 15 [set KNORTH 15]                                                                                                                                           ;; K(NORTH, CENTRE OR SOUTH) is a random constant that defines the technology of production (the higher K the more efficient will be the production) 
            set KCENTER random 15 if KCENTER < 10 [set KCENTER 10]
            set KSOUTH random 10 if KSOUTH = 0  [set KSOUTH 1 ]
            set N random-float 0.9                                                                                                                                                                        ;; a random constant "N" is added in order to generate the further complication. different firms can fix different levels of quality of the good sold: "N" is an indicator of quality. 
            if  N < 0.1 [set N 0.1]
            if  N >= 0.1 [if N < 0.3 [set QualityDiscountFactor 1.2]]
            if  N >= 0.3 [if N < 0.5 [set QualityDiscountFactor 0.9]]
            if  N >= 0.5 [if N < 0.7 [set QualityDiscountFactor 0.6]]
            if  N >= 0.7 [set QualityDiscountFactor 0.3]    
            set Mark-Up MarkUp]                                                                                                                                                                           ;; here we allow firms for the possibility of fixing a mark-up (again, a feature of a non-perfectly competitive environment), that for semplicity we assume to be equal to all firms. We create a slider so that we can change its value.                                                                                                                                                                                                                                                                                                                                                                                                                                          
end                                                                                                                                                                                                                           

                                                                                                                     


to go                                                                                                                                                                                                     ;; button.                                                                                                                    
  ifelse ticks < 1[search-for-job]                                                                                                                                                                        ;; search-for-job just allow the production to start, then the world to operationally exist. No consumption decision is taken into account here.                                                                                                                           
  [ifelse ticks < 2[produce]                                                                                                                                                                              ;; produce 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 different nominal wages and different prices 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 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.                                                                                                                   
            ifelse NumWorkers > 0
                              [set produce? 1                                                                                                                                                             ;; 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 color violet
                               
            ifelse quality [if ycor >= 28 [set production N * 6 * KNORTH * NumWorkers]                                                                                                                    ;; we don't assume that firms realize increasing or constant returns to scale anymore (as in the previous phases) but in order to introduce quality we have to make a different assumption, that is that firms realizes decreasing returns to scale: each worker employed produces less units of the good since he dedicates more time in the production of each single unit, thus increasing the quality of the good sold.                                                                                                                                                                
                               if ycor < 28 [if ycor >= 14 [set production N * 6 * KCENTER * NumWorkers]]                                                                                                 ;; production function will be then of the form: N (that is a number lower than 1 but larger than 0) that multiplies "K" (technology indicator) and the number of workers employed. 
                               if ycor < 14 [set production N * 6 * KSOUTH * NumWorkers]]
                              [if ycor >= 28 [set production 6 * KNORTH * NumWorkers]                                                                                         
                               if ycor < 28 [if ycor >= 14 [set production 6 * KCENTER * NumWorkers]]
                               if ycor < 14 [set production 6 * KSOUTH * NumWorkers]]]
              [set produce? 0 
               set production 0]]                
     
  
  ask frms [if ycor >= 28 [set costs ( 3 + NomWageNORTH * count wrkers with [pxcor = [pxcor] of myself and pycor = [pycor] of myself] )]                                                                  ;; in this phase we introduce a specification af the cost function (since it's necessary for our goal: the determination of the price chosen by each firm). Total costs are given by a fixed component (thet we set for semplicity equal to all firms) plus a variable component (given by the nominal wage multiplied by the number of workers employed).              
          if ycor < 28  [if ycor >= 14 [set costs ( 3 + NomWageCENTER * count wrkers with [pxcor = [pxcor] of myself and pycor = [pycor] of myself] )]]
          if ycor < 14  [set costs ( 3 + NomWageSOUTH * count wrkers with [pxcor = [pxcor] of myself and pycor = [pycor] of myself] )]
          set NumWorkers count wrkers with [pxcor = [pxcor] of myself and pycor = [pycor] of myself]
          if produce? = 1 [set UnitaryCost (costs / production)]                                                                                                                                          ;; since in order to calculate the unitary the use of production is needed, the level of quality will reflect in the sell price: the higher is the quality, the higher is the price. 
                           set price (UnitaryCost + Mark-Up)                                                                                                                                              ;; each firm set its sell price adding a murk-up to the unitary cost. So we end up with different prices fixed arbitralily by each firms ( a non-perfectly competitive world).
                           set stocks production
                           set price*prod (price * production)]                                                                                                                                           ;; we need to calculate a medium price in order to know the real wage. We set it equal to the sum of the units of goods produced by each firm multiplied by its own sell price, all divided by the total number of firm operating in the market. 
  
 
  set SumPrice*Prod sum [price*prod] of frms
  set SumProd sum [production] of frms
  set MediumPrice Sumprice*Prod / SumProd
    
  ask frms [if  ycor >= 28 [set RealWage NomWageNORTH / MediumPrice]
          if ycor < 28 [if ycor >= 14 [set RealWage NomWageSOUTH / MediumPrice]]
          if ycor < 14 [set RealWage NomWageSOUTH / Mediumprice]] 
  
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 [Realwage >= ([ReservSalary] of myself / MediumPrice)]                                                                              ;; in this procedure we take into account the complication of different nominal wages and different prices: workers choose randomly one of the firms in their radius that offer a real wage greater or equal to their reservation salary divided by the medium price. This happens after the first tick since, to determine unitary cost (and then price), it's necessary to calculate NumWorkers and it's possible only after having run the simulation once, with just the complication of different Nominal Wages taken into account, like in phase 1.
            set WhereIWork one-of frms in-radius searching-radiusW with [RealWage >= ([ReservSalary] of myself / MediumPrice)]]                                                                                                                              
ask wrkers [set IfICanBuy count frms in-radius searching-radiusC with [(price <= [wealth] of myself) and (price / QualityDiscountFactor <= [ReservPrice] of myself) and (produce? = 1) or (stocks > 0)]   ;; in this phase the further complication of different prices set by different firms modifies consumption-choices: consumers chooses randomly one of the firms that are in the smaller consumer-searching-radius that produce or have available stocks and that sell the good (that has the same quality everywhere) at a price that is lower or equal than their wealth. Again, this happens after the first tick since, to determine unitary cost (and then price), it's necessary to calculate NumWorkers and it's possible only after having run the simulation once, with just the complication of different Nominal Wages taken into account, like in phase 1.                                      ;; 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 with [(price <= [wealth] of myself) and (price / QualityDiscountFactor <= [ReservPrice] of myself) and (produce? = 1) or (stocks > 0)]                                                         
            ifelse FirmNearw > 0 [ifelse IfICanBuy > 0 [ move-to WhereIWork                                                                                                                               ;; if there's at least one firm in the worker-searching-radius that offers a real wage greater or equal to worker's reservation salary divided by medium price and that produces, then he starts to work turning his color into green. By working, he perceives the nominal wage increasing his wealth.
                                                         set color green      
                                                               if ycor >= 28 [set wage NomWageNORTH]
                                                               if ycor < 28 [if ycor >= 14 [set wage NomWageSOUTH]]
                                                                if ycor < 14 [set wage NomWageSOUTH]
                                                                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.
                                                                set wealth (wealth + wage)  
                                                                set work? 1
                                                          set SellingPrice [price] of WhereIBuy                                                                                                           ;; if there's at least one firm in the consumer-searching-radius that sells the good at a price that is lower or equal than consumer's wealth, then he purchases the good, increasing his size.
                                                          set buy? 1                                                                                                                                       
                                                          set size 2.1
                                                          set PiecesBought (PiecesBought + 1)                                                                                                             ;; if there's at least one firm in the consumer-searching-radius that sells the good at a price that is lower or equal than consumer's wealth, then he purchases the good, increasing his size.
                                                          set wealth (wealth - sellingprice)]       
                                                                
                                                      
                                    [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 size 1.3
                                     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 size 1.3
                                                                              set wealth (wealth - TravelCosts) 
                                                                              set LifePoints LifePoints - 1
                                                                              set ReservSalary (ReservSalary - 1)]]
                                                                                                                                      
ask wrkers [ifelse unemployment_benefit [if work? = 0 [if ycor >= 28 [set wage (0.5 * NomWageNORTH)]
                                                       if ycor < 28 [if ycor >= 14 [set wage (0.5 * NomWageSOUTH)]]
                                                       if ycor < 14 [set wage (0.5 * NomWageSOUTH)]
                                                       set wealth (wealth + wage)] 
                                                       if LifePoints < -5 [die]]
                                        [if LifePoints < 0 [die]]]                                                                                                                                        ;; if lifepoints decrease till becoming lower than zero, the agent dies.

 

                                                                                                                                                                                                                                                      
                                                                                     

ask frms [if ycor >= 28 [set costs ( 3 + NomWageNORTH * count wrkers with [pxcor = [pxcor] of myself and pycor = [pycor] of myself] )]         
          if ycor < 28  [if ycor >= 14 [set costs ( 3 + NomWageCENTER * count wrkers with [pxcor = [pxcor] of myself and pycor = [pycor] of myself] )]]
          if ycor < 14  [set costs ( 3 + NomWageSOUTH * count wrkers with [pxcor = [pxcor] of myself and pycor = [pycor] of myself] )]
          set NumWorkers count wrkers with [pxcor = [pxcor] of myself and pycor = [pycor] of myself]
          ifelse Numworkers > 0 [set produce? 1
                                 set color violet] 
                                [set produce? 0 
                                 set production 0]
          ifelse quality [if ycor >= 28 [set production N * 6 * KNORTH * NumWorkers]                                                                                         
                          if ycor < 28 [if ycor >= 14 [set production N * 6 * KCENTER * NumWorkers]]
                          if ycor < 14 [set production N * 6 * KSOUTH * NumWorkers]]
          [if ycor >= 28 [set production 6 * KNORTH * NumWorkers]                                                                                         
                          if ycor < 28 [if ycor >= 14 [set production 6 * KCENTER * NumWorkers]]
                          if ycor < 14 [set production 6 * KSOUTH * NumWorkers]]
          if produce? = 1 [set UnitaryCost (costs / production)]
                           set price (UnitaryCost + Mark-Up)
                           set stocks (stocks + production - count wrkers with [whereIBuy = myself])]

ask frms [set buyers count wrkers with [ WhereIBuy = myself ]                                                                                                                                              ;; to quantify the number of units of good sold by each firm.
          set PiecesSoldNow buyers                                                                                                                                                                         ;; we assume that each agent can purchase just one unit of good per tick.
          set PiecesSold (PiecesSold + buyers)
          ifelse benefit_for_firms [if ticks > 12 [if PiecesSold < 1 [die]]]
                                   [if PiecesSold < 1 [die]]                                                                                                                                               ;; there's a warehouse for each firm.
          if buyers > 2 [set size 3]                                                                                                                                                                       ;; the more a firm sells, the bigger it becomes. 
          if buyers > 7 [set size 4]   
 
          set  price*prod (price * production)]

set SumPrice*Prod sum [price*prod] of frms
set SumProd sum [production] of frms
set MediumPrice Sumprice*Prod / SumProd

ask frms [if  ycor >= 28 [set RealWage NomWageNORTH / MediumPrice]
          if ycor < 28 [if ycor >= 14 [set RealWage NomWageSOUTH / MediumPrice]]
          if ycor < 14 [set RealWage NomWageSOUTH / Mediumprice]] 
                                                                                                                                                                                                           ;; the more a firm produces, the bigger it becomes.                                  
                                                                                                                                       
show max-one-of frms [PiecesSold]                                                                                                                                                                          ;; to know which is the firm that sell more.
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.]                                                     
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