# Setting subset for regions

**URL:** <https://forum.mimiframework.org/t/setting-subset-for-regions/307>\
**Category:** Uncategorized\
**Created:** [September 1, 2024, 8:13am UTC](https://forum.mimiframework.org/t/setting-subset-for-regions/307 "2024-09-01T08:13:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![emilywen2001](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/emilywen2001/32/116_2.png) [@emilywen2001](https://forum.mimiframework.org/u/emilywen2001)\
**Post date:** [September 1, 2024, 8:13am UTC](https://forum.mimiframework.org/t/setting-subset-for-regions/307/1 "2024-09-01T08:13:07Z")

</div>

I tried to make some changes in the Mimi-RICE model to divide the regions index internally into two subsets of developing countries and developed countries. Is there any syntax in the mimi or Julia syntax that can do the following division?

---

<div class="post-metadata">

**Author:** ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)\
**Post date:** [September 3, 2024, 4:28am UTC](https://forum.mimiframework.org/t/setting-subset-for-regions/307/2 "2024-09-03T04:28:59Z")

</div>

Hi Emily,

Thanks for the question! To understand your end goals further, is the idea that you want to aggregate certain output variables using two subsets of the regions dimension of a model, or run the model itself using two subsets (developing and developed) of the built in regions dimension? Or perhaps something else?

Lisa

---

<div class="post-metadata">

**Author:** ![emilywen2001](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/emilywen2001/32/116_2.png) [@emilywen2001](https://forum.mimiframework.org/u/emilywen2001)\
**Post date:** [September 3, 2024, 7:39am UTC](https://forum.mimiframework.org/t/setting-subset-for-regions/307/3 "2024-09-03T07:39:15Z")

</div>

Hi Lisa, thanks for your reply!

I modified the original “neteconomy” module to provide different investment mechanisms for developing and developed regions (meaning different equations for different region types), and later to aggregate regional results. If you have the method to set subset, please let me know!

---

<div class="post-metadata">

**Author:** ![emilywen2001](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/emilywen2001/32/116_2.png) [@emilywen2001](https://forum.mimiframework.org/u/emilywen2001)\
**Post date:** [September 3, 2024, 9:17am UTC](https://forum.mimiframework.org/t/setting-subset-for-regions/307/4 "2024-09-03T09:17:04Z")

</div>

![image](https://canada1.discourse-cdn.com/flex031/uploads/mimiframework/original/1X/5e7aa19aadb397bdccec991a18a7197c5bc3eeee.png)  
BTW, I have tried this way of writing code, but it doesn’t work for me

---

<div class="post-metadata">

**Author:** ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)\
**Post date:** [September 3, 2024, 7:04pm UTC](https://forum.mimiframework.org/t/setting-subset-for-regions/307/5 "2024-09-03T19:04:02Z")

</div>

Got it thanks this is really helpful! So this is actually something in Mimi that I am actively working on right now [here](https://github.com/mimiframework/Mimi.jl/issues/948) so a few users, including myself, want to do something similar.

The basic issue is that `d` is a `NamedTuple` that only holds information on (1) dimension names and (2) how many elements there are in each dimension. It represents the indices as integers of 1 through size of dimension, which can then be used for indexing into `Parameter`s and `Variable`s, but _`d` does not contain information on the keys like “EU”_. If you typed

```auto
for r in d.regions
    println(r)
end

```

it would print

```auto
1
2
3 
...

```

And instead we want it to now be able to give us the actual keys. While I work on that, what I would suggest is externally figuring out which Integer indices apply to the subsets. The simplest way then would be:

```auto
for region in d.regions
   if r in [1,3,5,9]
       <do something>
   else 
       <do something else>
end

```

To add some structure to this and make it a bit more robust, you could actually create `Parameter`s for those sets of region indices. So then you’d end up with something like

```auto
# these use an anonymous dimension e.g. index = [4] that just tells the index how long your array will be, no need to use a named dimension here
developing_region_idxs = Parameter(index=[4]) # use an anonymous dimension for the size
developed_region_idxs = Parameter(index=[5]) # use an anonymous dimension for the size

for region in d.regions
   if r in p.developing_region_idxs
       <do something>
   elseif r in p.developed_region_idxs
       <do something else>
end

```

Then when building your model you would need to lookup what those indices are, either by hand or with some lookup function, and then set them

```auto
update_param!(m, :neteconomy, :developing_region_idxs, [1,3,5,9])
update_param!(m, :neteconomy, :developed_region_idxs, [2,4,6,7,8])

```

---

<div class="post-metadata">

**Author:** ![lrennels](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/lrennels/32/6_2.png) [@lrennels](https://forum.mimiframework.org/u/lrennels)\
**Post date:** [September 3, 2024, 7:06pm UTC](https://forum.mimiframework.org/t/setting-subset-for-regions/307/6 "2024-09-03T19:06:46Z")

</div>

Let me know how that goes, there are a few ways we could approach this.

---

<div class="post-metadata">

**Author:** ![emilywen2001](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.mimiframework.org/emilywen2001/32/116_2.png) [@emilywen2001](https://forum.mimiframework.org/u/emilywen2001)\
**Post date:** [September 4, 2024, 2:16am UTC](https://forum.mimiframework.org/t/setting-subset-for-regions/307/7 "2024-09-04T02:16:10Z")

</div>

Hi Lisa

I have tried your approach and it seems works for me! Thanks for your help!
