I am building a microsimulation model in Julia. I have built the structure of my function and it runs great for for 1 "person". I'd like to write the script to run 100000+ people through the model and save the results in one location.
Eventually I'd like to execute this in parallel.
Below I have included a simple working version of the code with dummy probabilities.
using Distributions
# Microsim function
function MicroSim(start_age, stages)
stage = 0
age = start_age
# Set all trackers to 0
Death_tracker = 0
Disease_tracker = 0
# While loop
while stage <= stages
age = age
###########################################################
# Probability of Death
pD = 0.02
if age == 100
pD = 1.0
else
pD = pD
end
# Coin flip
dist_pD = Bernoulli(pD)
Died = rand(dist_pD, 1)
if Died == [1]
Death_tracker = 1
# death tracker loop break
if Death_tracker == 1
# println("I died")
break
end
else
Death_tracker = Death_tracker
end
###########################################################
# Update age and stage
age = age + 1
stage = stage + 1
end
return age, Death_tracker
end
MicroSim(18,100)
for i in 1:100 println(MicroSim(18,100)) end
– Uhlan