calling time=x-1 data into an equation

Use this forum to post Vensim related questions.
Post Reply
kalegria
Junior Member
Posts: 14
Joined: Tue Jan 24, 2017 12:49 pm
Vensim version: DSS

calling time=x-1 data into an equation

Post 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
tomfid
Administrator
Posts: 3808
Joined: Wed May 24, 2006 4:54 am

Re: calling time=x-1 data into an equation

Post 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()).
kalegria
Junior Member
Posts: 14
Joined: Tue Jan 24, 2017 12:49 pm
Vensim version: DSS

Re: calling time=x-1 data into an equation

Post 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.
tomfid
Administrator
Posts: 3808
Joined: Wed May 24, 2006 4:54 am

Re: calling time=x-1 data into an equation

Post 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.
kalegria
Junior Member
Posts: 14
Joined: Tue Jan 24, 2017 12:49 pm
Vensim version: DSS

Re: calling time=x-1 data into an equation

Post 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.
tomfid
Administrator
Posts: 3808
Joined: Wed May 24, 2006 4:54 am

Re: calling time=x-1 data into an equation

Post 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.
swati
Junior Member
Posts: 11
Joined: Mon Jun 13, 2016 3:52 pm
Vensim version: PLE

Re: calling time=x-1 data into an equation

Post 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
Administrator
Super Administrator
Posts: 4589
Joined: Wed Mar 05, 2003 3:10 am

Re: calling time=x-1 data into an equation

Post by Administrator »

To quote Tom, "If you want the delayed value of a model variable, you can use DELAY FIXED.....".
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
tomfid
Administrator
Posts: 3808
Joined: Wed May 24, 2006 4:54 am

Re: calling time=x-1 data into an equation

Post 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
swati
Junior Member
Posts: 11
Joined: Mon Jun 13, 2016 3:52 pm
Vensim version: PLE

Re: calling time=x-1 data into an equation

Post by swati »

Thanks.this works perfectly for me. :)
Post Reply