Page 1 of 1
calling time=x-1 data into an equation
Posted: Fri Feb 10, 2017 4:14 pm
by kalegria
Hi,
I am trying to figure out how to include the data value at time=x-1 into an equation. How do I do that? For variable Z, I want Vensim at time=0 to use =z(initial)+Y*0.01, but at time=2, i'd like it to use =z(at time=1)+Y*0.01. At time=3, i want the equation to read =z(at time=2)+Y*0.01, etc. What is the correct format for the equation to achieve this? Thank you.
Kei
Re: calling time=x-1 data into an equation
Posted: Fri Feb 10, 2017 4:55 pm
by tomfid
You can use the TIME SHIFT function to generate a shifted version of the data -
https://www.vensim.com/documentation/in ... _shift.htm
You can also use GET DATA AT TIME,
https://www.vensim.com/documentation/in ... t_time.htm
Note that it's an expensive function call, so you want to use it sparingly (e.g., wrapped by INITIAL()).
Re: calling time=x-1 data into an equation
Posted: Fri Feb 10, 2017 7:16 pm
by kalegria
Thank you for your reply.
In both those solutions you mention, i would have to call out a specific time point, but I am interested in telling Vensim to use the data value in the previous time point (day-1) at every step (every day), except for time=1, where there would be an initial value that must be given, since there is no t=0. How could I tell Vensim, as I would in equations in Excel, to use the data value at time=x-1 to compute the value at time=x, for all time steps?
thank you.
Re: calling time=x-1 data into an equation
Posted: Fri Feb 10, 2017 7:38 pm
by tomfid
TIME SHIFT gives you a complete time series with the offset you specify.
At INITIAL TIME, it will look back into the data for a point at (INITIAL TIME-1), but if there is no such point, it will return the value at INITIAL TIME.
Re: calling time=x-1 data into an equation
Posted: Fri Feb 24, 2017 9:43 pm
by kalegria
Hi, I just tried using TIME <b>****</b>("variable name", -1), but i get this error message: "can only use data and constants in data equations "variable name".
Like i said before, I want to use the value calculated at time-1 for "variable name" in the equation, so that each value given an at time=x is a function of the calculated value for that variable at time-1.
Thank you.
Re: calling time=x-1 data into an equation
Posted: Fri Feb 24, 2017 10:27 pm
by tomfid
What I suggested is for data, per your original query. If you want the delayed value of a model variable, you can use DELAY FIXED or similar.
Re: calling time=x-1 data into an equation
Posted: Fri Mar 03, 2017 6:37 am
by swati
Hi
I have a similar query.I want to calculate growth rates of my stock variables.How can i do this in vensim ple? For example, I have a stock variable called aggregate output (Y). I want to calculate growth rate of Y using the formula : [Y(t) -Y(t-1)]/Y(t).
How do I get lagged value Y(t-1)?
Swati
Re: calling time=x-1 data into an equation
Posted: Fri Mar 03, 2017 7:47 am
by Administrator
To quote Tom, "If you want the delayed value of a model variable, you can use DELAY FIXED.....".
Re: calling time=x-1 data into an equation
Posted: Fri Mar 03, 2017 3:21 pm
by tomfid
Also, this is what the TREND function does, if the horizon equals one time step.
https://www.vensim.com/documentation/in ... _trend.htm
Re: calling time=x-1 data into an equation
Posted: Mon Mar 06, 2017 1:46 pm
by swati
Thanks.this works perfectly for me.
