Extract a value at a specified time from a stock

Use this forum to post Vensim related questions.
Post Reply
WayneZhou2009
Senior Member
Posts: 105
Joined: Wed Oct 25, 2017 3:52 pm
Vensim version: PRO

Extract a value at a specified time from a stock

Post by WayneZhou2009 »

Hi,

Is it possible to extract a value at a specified time from a stock? For example, my stock has the following values:

Year 2000, stock = 0
Year 2001, stock = 1
Year 2002, stock = 2
Year 2003, stock = 3
...

Year 2029, stock = 29
Year 2030, stock = 30

Is there a straightforward way to extract a value, say the value for year 2015, and assign it to another variable in the same model? I know this can be done "manually", but want to see if it can be done "automatically". I tried "SAMPLE IF TRUE" however the result returned is a constant line for all years after 2015, rather than just 1 single value point for year 2015.

Many thanks.
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: Extract a value at a specified time from a stock

Post by tomfid »

You can't extract the 2015 value from a stock throughout the run, because that would be acausal.

SAMPLE IF TRUE works if you want the 2015 value at 2015 or later. You can initialize the SAMPLE to :NA: if you want to be able to detect whether the sampling has happened yet.

If you need the future value at the start of the run, the only option is to run iteratively. There's a GET VDF function that you can use to extract the value from a previous run, though I don't remember the details.
Post Reply