nested subscripts

Use this forum to post Vensim related questions.
Post Reply
hallre
Junior Member
Posts: 3
Joined: Mon Jun 16, 2008 9:26 am

nested subscripts

Post by hallre »

dear all,

i use subscripts in a model to distinguish between different spatial entities -- say countries and continents.

now several elements in the country subscript relate to one element in the continents subscript (e.g. austria, belgium, denmark, ... all relate to europe)

i would like to sum a variable i calculated on the country level (e.g. CO2 emissions) to the continental level -- i.e. calculate, for each element of continents subscript, the sum of CO2 emissions over all constituent countries

my approach so far was to create to distinct subscripts for countries and continents, respectively. then i defined subranges of the country subscript that summarize all countries belonging to one continent. finally, i mapped the continent subscript on the continent subranges.

with this construction, i can use variables defined for continents in formulas on country level.

however, i couldn't find a way to do the transition from country to continent level -- which involves aggregation from country to continent level. no matter how i formulate the equation, i always end up with an error

any hints are highly appreciated!

thanks

reinhard
LAUJJL
Senior Member
Posts: 1477
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

Post by LAUJJL »

Hi Reinhard

The best is to join a model and explain what you are trying to do.
For instance the subscript countries: England, France, Austria, Canada, USA and the subranges of countries Europe : England,France,Austria and north America: Canada,USA.
Regards.
JJ
Administrator
Super Administrator
Posts: 4838
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

As JJ said, use subranges.

For example, you might have the following.

continent : Asia, Africa, North America, South America, Antarctica, Europe, Australia

country : england, ireland, scotland, argentina, brazil.

Now just change things a little. Introduce a sub range that is called european countries.

european countries : england, ireland, scotland

and change the country subscript
country : european countries, argentina, brazil.

Now you can calculate something like

CO2 Emissions[Europe] = sum (CO2 Emission by coutnry[european countries!])

CO2 Emissions[asia] = sum (CO2 Emission by country[asian countries!])


Hope all this makes sense.

Tony.
hallre
Junior Member
Posts: 3
Joined: Mon Jun 16, 2008 9:26 am

Post by hallre »

Thanks JJ and Tony for the replies.

I attached a small model where I included Tony's solution.

The solutions essentially consists in writing several equations for "CO2 emissions by continent" -- one for each element of the continent subscript.

However, I would strongly like to avoid writing multiple equations. I used continents and countries just for illustrative purposes -- in my actual model, "countries" are zones of a transport model (~1,000 zones) and "continents" (~100) are aggregates of several "countries". The number of "continents" and the assignment of "countries" to "continents" can change (between different simulations), which makes writing multiple equations cumbersome.

Returning to the example: Is there any "more elegant" way to calculate "CO2 emissions by continent" than to specify multiple equations for each continent?

I speculate there could be, because the way I mapped the "continents" subscript to the continent subranges (europerange etc.) of the countries subscript, Vensim already "knows" which country is part of which continent -- in the example, it correctly assigns emission factors by continent to individual countries.

Hope this is not too confused

Thanks again

Reinhard

BTW
I use Vensim DSS
Attachments
nested_subscripts.mdl
(2.92 KiB) Downloaded 444 times
LAUJJL
Senior Member
Posts: 1477
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

subscript range

Post by LAUJJL »

Hi Reinhard

It looks like you do not know how to create subranges.
You must study the Vensim user guide chapter devoted to
subscripts first and then study the defintions devoted to
subscript mapping.
Joined a simplistic model with a subscript with subranges
Just a remark.
Working with subscripts of high dimension like Hundreds of country is not going to help you understanding the dynamic of the whole model unless you have first built a highly aggregated model first.
Regards.
JJ
Attachments
subranges.mdl
(1.49 KiB) Downloaded 447 times
Lee Jones

Post by Lee Jones »

Hi,

I think I understand your requirement and the model you attached does indeed represent Tony's suggestion (and my preferred method). I have attached an alternative that will avoid multiple equations for the summation exercise.

Cheers

Lee
Attachments
nested_subscripts[2].mdl
(2.99 KiB) Downloaded 480 times
bob@vensim.com
Senior Member
Posts: 1107
Joined: Wed Mar 12, 2003 2:46 pm

Post by bob@vensim.com »

In addition to Lee's example you can also use the VECTOR SELECT function. The example moving between age cohort aggregations in the Reference Manual is directly applicable to your case.
hallre
Junior Member
Posts: 3
Joined: Mon Jun 16, 2008 9:26 am

Post by hallre »

Thanks for the help! Both solutions are perfectly suitable for my purposes...

Reinhard
Post Reply