Wealth Distribution

Wealth Distribution preview image

1 collaborator

Default-person Juliette Miller (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by the author
Model was written in NetLogo 5.3.1 • Viewed 300 times • Downloaded 22 times • Run 0 times
Download the 'Wealth Distribution' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

; Juliette Miller
; Trade Model
extensions [matrix]

globals [
  gini-index
  gini-index_
  lorenz-points
  n           ; number of turtles
  B_ave       ; average budget
  B_diff      ; difference in budgets
  fs_ave      ;
  beta_ave    ; average beta (of patches)
  alpha_ave   ; average alpha (of turtles)
  wage_ave    ; average wage of turtles

  edu_skld
  retire_age
  dead
  Skld_Ratio
  NoProd
  ]

turtles-own [ ; turtles are workers
  B  ; budget
  B_ ; lagged budget
  X  ; current consumption
  X_ ; lagged consumption
  Y  ; future consumption/ amount they are saving
  alpha     ; preference for current consumption/ marginal propensity to consume
  U         ; utility function
  working?  ; have a job
  purchase? ; demand realized by successful purchase
  W         ; wages
  yrs_wk    ; years a turtle has worked; one year = 1 sweep
  wtot      ; total wages earned
  fs        ; frustrated sale / forced saving
  edu         ; education
  age
  unempl      ; unemployment
  in_school?
  inher
  heirs
]


patches-own [ ; patches are firms
  Q      ; output
  Q_     ; lagged output
  beta   ; share of capital ; elasticity of output with respect to capital
  K      ; capital stock
  L      ; labor demand
  MPL    ; marginal product of labor
  prof   ; residual after paying wages ; profit
  inven  ; inventory
  inven_ ; lagged inventory
  p      ; price
  p_     ; lagged price
  costs  ; costs of production
  r      ; rate of interest
  sd     ; demand for skilled labor
  dinven_list
  inv
  invested? ; has patch invested?
]

to setup
    clear-all
    set edu_skld 14
    set retire_age 70
    set n 500  ; start with 500 turtles
    set lorenz-points []
    setup-patches
    setup-turtles
    update-lorenz-and-gini
    set gini-index_ 0
    reset-ticks
end 

to setup-patches ; setup firms
  ask patches [
    set pcolor blue - 2
    set beta 0.05 + random-float 0.35   ;.7    ; 0.1 + random-float 0.35  ; between 0.1 and 0.45 ; bg: random float 0.35
    set K random 10                     ; distribute capital stock so that there can be some unemployment (if K=0)
    set inven 5
    set inven_ 0
    set Q 1
    set Q_ 1
    set p 1
    set p_ 1
    set invested? false
    if K = 0 [
      set pcolor grey
      ]
    set dinven_list []
 ]
  ;set skilled labor demand
  ask patches [set sd skl_lab K]
  set beta_ave (sum [beta] of patches / count patches)
end 

to setup-turtles
  create-turtles n [; uses value of number slider to create turtles
    set alpha (.2 + random-float .8)  ; between .2 and .10
    set B 1 + random 4              ;random 5 ;random 50 causes too much demand
    setxy random-xcor random-ycor   ; turtles are placed on a random spot on the grid
    set U 1
    set W 1  ; wage rate
    set shape "circle 2"
    set size 0.75
    set in_school? false
    set age 6 + random 65
    if in_school? = true [move-to one-of patches with [k = 0]] ; put turtles on a patch
    set heirs 1 + random 10
    set edu yrs_edu age]
    set alpha_ave (sum [alpha] of turtles / count turtles)
end 

to-report skl_lab [cap]
     let sd_ 20 * (1 - 1 / (2 * exp (0.3 * K)))
     report sd_
end 

to-report yrs_edu [yrs_age]
    let ed 0
    let edu_max yrs_age - 6    ;  the amount of educuation if stayed in school
    let drop_out yrs_age - 16  ;  years in which dropping out of school is legally possible
    if yrs_age <= 16
     [set ed edu_max set in_school?  true]

    if (yrs_age >= 16 and yrs_age <= 24)
    [ifelse (random-float 1 < (1 - drop_out * .1) )
     [set ed edu_max set in_school?  true ]
     [set ed edu_max - (1 + random drop_out) set in_school?  false ]]

     let tmp_float random-float 1
     ;print tmp_float
   if (yrs_age >= 25 and yrs_age <= 34)  [ifelse tmp_float <  0.109
                                          [set ed 17 + random 4]
                                           [ifelse tmp_float < 0.361
                                            [set ed 16]
                                             [ifelse tmp_float < 0.465
                                              [set ed 14 + random 2]
                                               [ifelse tmp_float < 0.65
                                                [set ed 13 ]
                                                 [ifelse tmp_float < 0.905
                                                   [set ed 12]
                                                    [set ed 11 - random 2]
                                                     ]]]]]
    ;print yrs_age
    ;print ed

     set tmp_float random-float 1
  if (yrs_age >= 35 and yrs_age <= 44)  [ifelse tmp_float  < 0.138
                                          [set ed 17 + random 4]
                                           [ifelse tmp_float  < 0.363
                                            [set ed 16]
                                             [ifelse tmp_float  < 0.467
                                              [set ed 14 + random 2]
                                               [ifelse tmp_float  < 0.628
                                                [set ed 13 ]
                                                  [ifelse tmp_float  < 0.887
                                                   [set ed 12]
                                                    [set ed 11 - random 2]
                                                       ]]]]]
    set tmp_float random-float 1
  if (yrs_age >= 45 and yrs_age <= 64)  [ifelse tmp_float  < 0.121
                                          [set ed 17 + random 4]
                                           [ifelse tmp_float  < 0.32
                                            [set ed 16]
                                             [ifelse tmp_float  < 0.426
                                              [set ed 14 + random 2]
                                               [ifelse tmp_float  < 0.59
                                                [set ed 13 ]
                                                 [ifelse tmp_float  < 0.894
                                                  [set ed 12]
                                                   [set ed 11 - random 2]
                                                       ]]]]]
     set tmp_float random-float 1
   if (yrs_age >= 65)                    [ifelse tmp_float  < 0.113
                                          [set ed 17 + random 4]
                                           [ifelse tmp_float  < 0.267
                                            [set ed 16]
                                             [ifelse tmp_float  < 0.341
                                              [set ed 14 + random 2]
                                               [ifelse tmp_float  < 0.497
                                                [set ed 13 ]
                                                  [ifelse tmp_float  < 0.843
                                                   [set ed 12]
                                                    [set ed 11 - random 2]
                                                       ]]]]]

   ;type " edu = " type ed type " age = " print yrs_age
   report ed
end 


;; MAIN ROUTINE, repeats every tick

to go
  if ticks > 5 and abs (gini-index - gini-index_) < 0.001 [stop]  ; <=
  save-lagged
  ;;update-price            ; change price based on inventory adjustment
  retire
  school
  look-for-job
  produce
  demand
  update-budget
  update-lorenz-and-gini
  tick
end 

;; Save certain variables from the previous sweep.

to save-lagged
  ;print("Saving lagged...")
  set gini-index_ gini-index

 ;ask patches [
    ;set inven_ inven
    ;set p_ p
    ;set Q_ Q ]

      ask patches
  [
    set dinven_list  lput (inven - inven_)  dinven_list
    if length dinven_list > 100 [set dinven_list butlast dinven_list]
    set inven_ inven
    set p_ p

    let tmp item 2 matrix:forecast-linear-growth dinven_list
  ifelse (tmp >= -.001) [                                          ; positive slope implies positive forecast
    set inv 0
    ;print "don't invest"
    ][
    set inv 1 invest
    ]

   ]


  ask turtles [
    set X_ X
    set B_ B
    ifelse working? = false [set unempl unempl + 1] [set unempl 0]
    set working? false
    set purchase? false
    set age age + 1
    if in_school? = true [set edu edu + 1]
    set in_school? false
    ]
end 

to retire
 ;print "retiring"
 let benefit 0
 ask turtles
 [if age > retire_age
 [set dead dead + 1
   set inher B / ( heirs + 1 )
   set benefit inher
   ;type "inher of turtle " type who type " in the amount of "  print inher
   repeat heirs  ; repeat for the number of heirs
     [
    ; type " heirs = " print heirs
     ask one-of other turtles
       [set B B + benefit
     ;   type "inher received by " type who type " in the amount of " print benefit
         ]
     ]

 ;budget of offspring

 set B inher
 set age 1 + random 6
 ;print age
 set edu yrs_edu age
 set alpha alpha + .1 *  (.5 - random-float 1)                 ; Give offspring a new alpha
 if alpha > .9  [set alpha .9 ]   ;  ad hoc
 if alpha < .1  [set alpha .1 ]   ;  ad hoc
   ]
 ]
end 

to school
  ;print "schooling"
ask  turtles with [unempl > 4 and edu <= 16 ]
[ let x_min  alpha * B / (2 * mean [p] of patches )  ;  go to starvation consumption
  let yrs_schl  B / x_min   ;  finance school with savings

  ifelse (yrs_schl >= 1) [ set alpha alpha / 2
                    move-to one-of patches with [K = 0]
                    set in_school? true
                     ]

                  [ set in_school? false ] ; can't afford school
]
end 

to look-for-job
  ;print("Looking for job...")
  ask turtles with [in_school? = false]
    [right random 360
    forward 3
    if edu >= [sd] of patch-here
    [set working? true
      set unempl 0]

    ;if [k] of patch-here > 0  ; if patch has capital it can employ workers
      ;[set working? TRUE
     ; set yrs_wk yrs_wk + 1]
    ]
end 

;; PATCHES PRODUCE

to produce  ; firms produce
  ;print("Producing...")
  ask patches [
    set L count turtles-here with [working? = true]       ; each turtle supplies one unit of labor
    set Q K ^ beta * L ^ (1 - beta) ; Cobb-Douglas Production Function where K is captial, L is labor, and beta is the output elasticity
    set inven inven_ + Q            ; Q goes to inventory ; add Q to lagged inventory
    set Q_ Q
    ifelse L > 0  ; putting at top of produce procedure would mean we would have to set Q = 0
    [set MPL (1 - beta) * (K / L) ^ beta]            ; determine marginal product if producing ; set MPL = wage rate
    [set MPL 0
     set Q 0]                                        ; if not then set to 0


    ask turtles-here [if working? = true
      [set W P * MPL]]             ; inter-agent communication; this is a nominal wage (real is w/p) based on last price paid


    ifelse Q > 0                            ; if patches are producing [set costs and profits] if not [costs = 0, profits = 0]
     [set costs (P * MPL * L)               ; originally p * MPL * L ; changed for minimum wage below
       set prof p * Q - costs
       set pcolor green + 3]
     [set costs 0
       set prof 0
       set pcolor blue + 3]
     if K = 0 [set pcolor gray]
     ]
  set wage_ave (sum [W] of turtles / count turtles)

  ifelse (count turtles with [working? = true AND edu >= [sd] of patch-here AND edu < 14]) > 0

 [ set Skld_Ratio ((count turtles with [working? = true AND edu >= [sd] of patch-here AND edu >= 14]) / (count turtles with [working? = true AND edu >= [sd] of patch-here AND edu < 14])) ]
 [ set Skld_Ratio 0 ]

  set NoProd count patches with [K > 0 and L = 0]
end 



;; TURTLES GO SHOPPING

to demand
  ;print("Demanding...")
  ask turtles [
    right random 360
    forward 3
    set X alpha * B / [p] of patch-here    ; sets demand according to price on patch-- this can vary
    ;set Y (B - [p] of patch-here) * X
    ifelse X <= inven     ; turtle makes purchase if inventory is sufficient
    [set purchase? true
      set inven inven - X]; adjust inventory
    [set X inven          ; buy remaining inventory
      set fs fs + 1       ; record frustrated sale
      set inven inven - X ; inven should be 0
      if X > 0 [set purchase? true] ; don't say purchase is true if the quantity demanded is 0
    ]

    ;now update turtle utility ;compute U
    set Y (1 - alpha) * B
    set U X ^ alpha * Y ^ (1 - alpha)  ; utility

    if in_school? = true [move-to one-of patches with [k = 0]]; go back to school

  ]
  set fs_ave sum [fs] of turtles / count turtles
end 

to invest
  ;repeat 10 [
  ;print "investing"
    ask one-of patches with [inv > 0 ]
    [ set invested? true
      let d_inv  0.1 * K
      while  [d_inv > 0]
       [let supplier one-of other patches with [inven > 0]
         ifelse (supplier = nobody)
          [set d_inv  0]
          [ifelse  d_inv <  [inven] of supplier
           [set K K + d_inv set d_inv 0
            ask supplier [ set inven inven - d_inv  ]]
          [set K K + [inven] of supplier
            set d_inv d_inv - [inven] of supplier
            ask supplier [ set inven 0]]
       ]
     ]
      set sd skl_lab K  ; upgrade skill demand
    ] ;]
end 

to update-budget

    ;print("Updating budget...")
    ask turtles [
      if purchase? = true [
        set B B - p * X]    ; use p if not pc ; set B B - pc * X
      ifelse working? = true
      [set B B + W          ; budget plus what earned this period (w)
        set wtot wtot + w   ; wage total = wage total + w
        set color blue
        ]
      [set color red
        ]

      let prof_sum sum [prof] of patches  ;All profits earned in the model
      let B_sum sum [B_] of turtles       ;Sum of turtle budgets ; changed from B to B_
      set B B + B_ / B_Sum * prof_sum     ;distribute profits of patches to turtles in proportion to turtles weath (presumably deposited in some banking system behind the scenes)

    ]
end 

to update-lorenz-and-gini
  ;print("Lorenz...")
  let sorted-wealths sort [B] of turtles
  let total-wealth sum sorted-wealths
  let wealth-sum-so-far 0
  let index 0
  set gini-index 0
  set lorenz-points []  ; a list
  repeat n [
    set wealth-sum-so-far (wealth-sum-so-far + item index sorted-wealths)
    set lorenz-points lput ((wealth-sum-so-far / total-wealth) * 100) lorenz-points
    set index (index + 1)
    set gini-index gini-index + (index / n) - (wealth-sum-so-far / total-wealth)]
end 

; SAM is in nominal terms; SAM is for 1 year; purchases must be false when tick starts ; c_ is reported under the guise of c to the rest of the program

to-report C  ;total consumption
    let C_ sum [ p * X ] of turtles with [purchase? = true] ; [pc * x]
    report C_
end 

to-report I ; total investment
    let I_ sum [p * (inven - inven_)] of patches
    report I_
end 

to-report VA  ; value added
    let VA_ sum [w] of turtles with [working? = true] + sum [prof] of patches
    report VA_
end 

to-report Wages
    let Wages_ sum [w] of turtles with [working? = true]
    report Wages_
end 

to-report Profits
    let Profits_ sum [prof] of patches
    report Profits_
end 

to-report Yh  ; household income
   let Yh_ sum [w] of turtles with [working? = true] + sum [prof] of patches
   report Yh_
end 

to-report S  ; household savings
    let S_ sum [w] of turtles with [working? = true] + sum [prof] of patches
     - sum [p * X] of turtles with [purchase? = true]   ; - sum [pc * X] of turtles with [purchase? = true]
     report S_
end 

to-report GDP
      report sum [p * Q] of patches ; nominal GDP
end 

to-report SI-err
      let I_ sum [P * (inven - inven_) ] of patches

      ;let S_ sum [w] of turtles with [working? = true] + sum [prof] of patches - sum [p * X] of turtles with [purchase? = true]
      let delta_wealth sum [B] of turtles - sum [B_] of turtles
      report delta_wealth - I_
      ;report S - I
end 

to-report g
      let g_ ((gini-index / n) / 0.5)
      report g_
end 

to-report g_lagged
      let g__ ((gini-index_ / n) / 0.5)
      report g__
end 

There is only one version of this model, created over 8 years ago by Juliette Miller.

Attached files

File Type Description Last updated
Wealth Distribution.png preview Preview for 'Wealth Distribution' over 8 years ago, by Juliette Miller Download

This model does not have any ancestors.

This model does not have any descendants.