User Tools

Site Tools


howtos:implementagingwithmap:apply_aging_using_a_map

This is an old revision of the document!


Implement aging using a map

If you need to age a stock by 1 year you can create a map which moves all stock up 1 in the age sequence and bins the last 2 years with the following code:

integer $firstAge = 0
integer $lastAge = 100

local eafrToea[ea,eafr] = create (; dim=SEQ:age;$firstAge;$lastAge;1:year, \
	dim=SEQ:ageFr;$firstAge;$lastAge;1:year)
eafrToea[ea,eafr] = insert (extract (diag (1.0; \
	dimFrom1=eafrToea[ea,eafr]); \
	age:+0..-1); \ 
	age->age:+1, ageFr->ageFr:+0) !This moves the diagonal forward one age so n year olds map to (n+1)1 year olds
eafrToea[ea,eafr] = insert (1.0; age:-0, ageFr:-0) ! this does the binning of the last 2 ages

Now you can just apply the map to your stock (not the change of sequence name just before the map!):

local agedStock[upperDims,ea] = map (changeseq (stock[upperDims,ea]; \
   dim=age, name=ageFr), \
   eafrToea[ea,eafr])
howtos/implementagingwithmap/apply_aging_using_a_map.1287494007.txt.gz · Last modified: 2010/10/19 13:13 by shona.weldon