EKC
No preview image
Model was written in NetLogo 5.3.1
•
Viewed 265 times
•
Downloaded 40 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
The construction of this model is described in Tutorial 3 in the NetLogo User Manual.
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
extensions [matrix]
; 6 is the minium age for edu
; max edu is 20
; min edu is 10
; skilled edu > 14
; unskilled edu 10-14
; according to CPS
; http://www.census.gov/content/dam/Census/library/publications/2016/demo/p20-578.pdf
; working history
globals [ ; average price level
data
gini-index
gini_
lorenz-points
n ; number of turtles
n_trans ; number of transfers
trans_tot
transfers? ; default is true
frustrated_sales? ; default is true
retire_age
dead
filename
hcount
edu_skld ; years to become skld
grad_count
tax_rate ; household tax rate
GDP_ ; LAGGED GDP
P-content ; Phosphorous content in lake
absorbtion ; Amount of phosphorous absorbed by lake per sweep
G ; govt spending on goods and services
;
]
turtles-own [
B ; budget
B_ ; lagged budget
X ; goods
X_
Y ; future consumption
alpha ; preference
U ; utility
working? ; have a job
purchase?
w ; wages
wtot
fs ; frustrated sales
tax
transfers
edu ; education
age ; age
inher
heirs
unempl ; unemployment
in_school? ;
aff_schl? ;
]
patches-own
[Q ; output
Q_ ; lagged output
beta ; elas of output with respect to capital
K ; capital stock
L ; labor demand
MPL ; MPL
prof ; residual after paying wages
inven ; inven
inven_ ; inven lagged
p ; price
p_ ; price lagged
costs ;
sd ; demand for skilled labor
patch-type ; "farm", "residential", or "firm"
P-rate ; Function of distance from line x=0 (lake), K, and patch type.
inv ; investment
dinven_list ; change in inventory list
gamma
ext ; extrenalities
]
to setup
clear-all
set tax_rate 0
set G 0
set edu_skld 14
set retire_age 70
set transfers? true
set frustrated_sales? false
set n 500
set lorenz-points []
setup-patches
setup-turtles
update-lorenz-and-gini
set gini_ 0
reset-ticks
end
to setup-patches
ask patches
[
set pcolor blue - 2
set beta 0.05 + random-float .35 ;
set K random 10 ; some capital stock between 0 and 9
set inven 5
set inven_ 0
set Q 1
set Q_ 1
set p 1
set p_ 1
set ext 0
set gamma 0.3 + random-float .4
if K = 0
[set pcolor gray]
; Of patches with K > 0,
; 40% are farms and
; 60% are firms.
; Patches with K = 0 are residential.
ifelse random 10 < 4 [
set patch-type "farm"
set pcolor 50 + K ; color farms with more capital darker.
][
set patch-type "firm"
set pcolor 100 + K ; color firms
]
set patch-type "residential"
set dinven_list []
]
; set skilled labor demand
ask patches [ set sd skl_lab K]
end
to setup-turtles
create-turtles n
[ set alpha (0.2 + random-float 0.8)
set aff_schl? true
set w 1
set B 1 + random 4
setxy random-xcor random-ycor
set U 1
set shape "circle"
set size .5
set in_school? false
set age 6 + random 65
if in_school? = true [move-to one-of patches with [k = 0]]
set heirs 1 + random 10
set edu yrs_edu age ; notice passing of data age
]
debug-print
end
to-report skl_lab [cap]
let maxK max [K] of patches
let sd_ 10 + 10 * cap / maxK
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
to debug-print
let tmp 16
repeat 54 [
type tmp type " = " type count turtles with [edu < 12 and age = tmp]
type " of " print count turtles with [age = tmp]
set tmp tmp + 1
]
type "total = " type count turtles with [edu < 12 and age >= 18]
type " of " print count turtles with [age >= 18]
type "high school or better " print precision (100 * count turtles with
[edu >= 12 and age >= 25] / count turtles with [age >= 25]) 2
type "associates or better " print precision (100 * count turtles with
[edu >= 14 and age >= 25] / count turtles with [age >= 25]) 2
type "college or better " print precision (100 * count turtles with
[edu >= 16 and age >= 25] / count turtles with [age >= 25]) 2
type "grad " print precision (100 * count turtles with
[edu >= 18 and age >= 25] / count turtles with [age >= 25]) 2
end
to go
if (abs ( gini-index - gini_) < .001 ) [ big-data stop ]
; update-price ; change price based on inventory adjustment
save-lagged ; current data as lagged before the rest of go changes it
retire
school
look-for-job ; turtle procedure
produce ; patch procedure production preceeds consumption
demand ; turtle procedure uses B from the past
; get ready for next round
update-budget ; for next period
update-lorenz-and-gini
tick
end
to save-lagged
set gini_ gini-index
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 aff_schl? true
set X_ X
set B_ B
ifelse working? = false [set unempl unempl + 1][set unempl 0] ; reset unempl if found job
set working? false
set purchase? false
set age age + 1
if in_school? = true [set edu edu + 1]
set in_school? false
set transfers 0
set tax 0
]
end
to retire
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
[
; 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
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 ]
]
end
to look-for-job
ask turtles with [in_school? = false]
[right random 360
forward 3
if edu >= [sd] of patch-here
;[ if ss > [sd] of patch-here [print "over qualified"]
; if ss = [sd] of patch-here [print "qualified"]
[set working? TRUE set unempl 0
;set color white print working?
]
]
end
to produce
ask patches
[
set L count turtles-here with [working? = true] ; each turtle supplies one unit of labor
;type " L = " print L
set Q K ^ beta * L ^ (1 - beta) ; production function
set inven inven_ + Q ; add Q to inventory
set Q_ Q
ifelse L > 0
[set MPL ( 1 - beta ) * (K / L) ^ beta ] ; determine marginal product if producing
[set MPL 0 set Q 0] ; if not then set to zero
ask turtles-here
[if (working? = true) [set w p * MPL]] ; this is a nominal wage based on the last price paid
ifelse Q > 0
[ set costs p * MPL * L set prof p * Q - costs set pcolor green - 1]
[ set costs 0 set prof 0 set pcolor blue - 1]
if K = 0
[set pcolor gray ]
if K > 0
[set ext (Q / K) ^ gamma]
]
end
to demand ; since more than one turtle can arrive on the same patch
; different turtles pay different prices
ask turtles [
right random 360 ; turtle arrives on new patch--may be the second to arrive
forward 3
set X alpha * B / [p] of patch-here
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 ; should bezero
if X > 0 [set purchase? true] ; don't say purchase is true if the the quantity is zero
] ;
; now update turtle utility
set Y (1 - alpha) * B ; compute Y
set U X ^ alpha * Y ^ ( 1 - alpha ) ; utility
if in_school? = true [move-to one-of patches with [k = 0]]; go back to school
]
end
to invest
ask one-of patches with [inv > 0 ]
[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
ask turtles
[ if purchase? = true
[set B B - p * X] ; what you didn't spend goes into next period's savings
ifelse working? = true
[set B B + w set wtot wtot + w set color blue ]
[set color red if (in_school? = true) [set color yellow]]
let prof_sum sum [prof] of patches
let B_sum sum [B_] of turtles ; distribuion is based on this period's savings
set B B + B_ / B_sum * prof_sum
; now tax rich and redistribute to poor tax rate is exogenous
]
let n_rich 0.2 * n
let rich max-n-of n_rich turtles [B]
ask rich
[
set tax tax_rate * B
set B B - tax
]
let n_poor count turtles with [tax = 0]
let trans_total sum [tax] of turtles
ask turtles with [tax = 0]
[set transfers trans_total / n_poor
set B B + transfers ]
end
to update-price
ask patches [ ; increase or decrease price
if Q != 0 [
ifelse inven / Q > inven_ / Q_
[set p p_ * 0.98 ]
[set p p_ * 1.02 ]
]
]
end
; make SAM
to-report C ; total consumption
let C_ sum [ p * X ] of turtles with [purchase? = TRUE]
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 ; value added
let Wages_ sum [w] of turtles with [working? = TRUE]
report Wages_
end
to-report Profits ; value added
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 + sum [transfers] of turtles
report Yh_
end
to-report S ; household
let S_ sum [w] of turtles with [working? = TRUE] + sum [prof] of patches
- sum [ p * X ] of turtles with [purchase? = TRUE]
- sum [tax] of turtles + sum [transfers] of turtles
report S_
end
to-report GDP
report sum [p * Q] of patches ;
end
to-report pollution
let ext_ sum [ext] of patches
report ext_
end
to-report Tr
let Tr_ sum [transfers] of turtles ;
report Tr_
end
to-report Yg
let Yg_ sum [tax] of turtles ;
report Yg_
end
to-report Sg
let Sg_ Yg - Tr ;
report Sg_
end
to-report SI-err
let I_ sum [p * (inven - inven_) ] of patches
let delta_wealth sum [B] of turtles - sum[B_] of turtles
report Sg + delta_wealth - I_ ; total savings of turtles minus investment
end
to big-data
set filename "data.csv"
if hcount = 0
[write-csv filename (list "who" "alpha" "B" "yrs_wk" "yrs_wks" "wtot" "fs" "tax" "transfers" )]
ask turtles [ write-csv filename (list who alpha B wtot fs tax transfers) ]
set hcount hcount + 1
end
to write-csv [ #filename #items ] ;; #items is a list of the data (or headers!) to write.
if is-list? #items and not empty? #items
[ file-open #filename
;; quote non-numeric items
set #items map quote #items
;; print the items
;; if only one item, print it.
ifelse length #items = 1 [ file-print first #items ]
[file-print reduce [ (word ?1 "," ?2) ] #items]
;; close-up
file-close
]
end
to-report quote [ #thing ]
ifelse is-number? #thing
[ report #thing ]
[ report (word "\"" #thing "\"") ]
end
to-report te_rule
let n_rich 0.2 * n
let B_tot sum [B] of turtles
let B_rich sum [B] of max-n-of n_rich turtles [B]
let te_rule_ B_rich / B_tot
report te_rule_
end
;; this procedure recomputes the value of gini-index-reserve
;; and the points in lorenz-points for the Lorenz and Gini-Index plots
to update-lorenz-and-gini
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
;; now actually plot the Lorenz curve -- along the way, we also
;; calculate the Gini index.
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
There is only one version of this model, created almost 9 years ago by Avery Baratz.
Attached files
No files
This model does not have any ancestors.
This model does not have any descendants.
Download this model