how to count the repetition of a specific value of a variable in every time unit?

Use this forum to discuss any issues relating to Systems Dynamics and Systems Thinking.
Post Reply
ehsun
Junior Member
Posts: 3
Joined: Mon Jun 17, 2019 10:32 am
Vensim version: PLE

how to count the repetition of a specific value of a variable in every time unit?

Post by ehsun »

hello
I have made a very simple model in Vensim,
in this model, the unit of time is "year", starting time is "0", finishing time is "5" and the time step is "0.25" (which means I do the simulation 4 times a year)
there is a variable which generates random normal numbers with 0 mean and 1 standard deviation in my model: RANDOM NORMAL( -10, 10, 0, 1, 1)
here are the random numbers:
time,random number
0,-1.04477
0.25,-1.46777
0.5,1.4296
0.75,1.12405
1,-0.75553
1.25,0.71774
1.5,-1.0112
1.75,0.907354
2,-1.63352
2.25,0.358083
2.5,-0.592134
2.75,-0.502384
3,-0.15921
3.25,1.03012
3.5,0.495428
3.75,0.00491477
4,-0.170177
4.25,-1.10765
4.5,-1.43189
4.75,0.176147
5,-0.0711939

I simply separate negative numbers from positive ones into 2 different variables:
variables A: IF THEN ELSE( random number>0, 1, 0)
Variable B: IF THEN ELSE( random number<=0, 1, 0)

time,variable A,time,variable B
0,0,0,1
0.25,0,0.25,1
0.5,1,0.5,0
0.75,1,0.75,0
1,0,1,1
1.25,1,1.25,0
1.5,0,1.5,1
1.75,1,1.75,0
2,0,2,1
2.25,1,2.25,0
2.5,0,2.5,1
2.75,0,2.75,1
3,0,3,1
3.25,1,3.25,0
3.5,1,3.5,0
3.75,1,3.75,0
4,0,4,1
4.25,0,4.25,1
4.5,0,4.5,1
4.75,1,4.75,0
5,0,5,1


now what I need to do is to count the number of "ones" in every "time unit".
for example: for variable A:
in the first time unit, we have 2 "ones"
in the second time unit, we have 2 "ones"
in the third time unit, we have 1 "one"
in the fourth time unit, we have 3 "ones"
an in the last time unit, we have 1 "one"

it was not possible to put numbers in a table, so I used comma to separate the them.

I don't know how to do it.
I would be really grateful if you could help me with this.
thanks in advance
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: how to count the repetition of a specific value of a variable in every time unit?

Post by Administrator »

Try the following.

value found flag = if then else ( variable a = 1 , 1 , 0 )

total samples = integ ( value found flag / time step , 0 )
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
ehsun
Junior Member
Posts: 3
Joined: Mon Jun 17, 2019 10:32 am
Vensim version: PLE

Re: how to count the repetition of a specific value of a variable in every time unit?

Post by ehsun »

this is not what I am looking for,
I don't want to accumulate all the ones in one stock and I want my stock to become 0 after every time unit.
I mean I want to have a variable that gets the value of 2 in the first time unit, then gets the value of 2 in the second time unit, then gets the value of 1 in the third time unit and so on.
is it possible?
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: how to count the repetition of a specific value of a variable in every time unit?

Post by Administrator »

Can you upload the model?
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
ehsun
Junior Member
Posts: 3
Joined: Mon Jun 17, 2019 10:32 am
Vensim version: PLE

Re: how to count the repetition of a specific value of a variable in every time unit?

Post by ehsun »

I realized my mistake and managed to solve the problem.
thanks a lot.
Post Reply