random assigment of municipality id's to households.

17 views
Skip to first unread message

Ingrid Schockaert

unread,
Feb 19, 2019, 4:38:46 AM2/19/19
to liam2-users
Dear all,

To simulate the internal emigrations of households to 47 destinations (groups of municipalities indicated by field indx), 
I use the following code
ENTITY=HOUSEHOLD
- int_migration_targets: load('int_migration_targets.csv', type=int)
                - indx2: 1
                - new_mun: -1
                - while indx2 <=47:
                    - need: int_migration_targets[:,:,:,indx]  ##number of emigration to each destination (indx) by age,sex,householdposition
                    - target: TARGET[indx,:,:]   ##probability of emigration by municipality to each destination (47 groups of municipalities: table "indx,res_id,period")
                    - logitscore: logit_score(0.0) ##to be defined 
                    - is_candidate: align(logitscore,target, leave=persons.count(age>88)>0 or num_person>7 or new_mun>-1)
                    - migrant_pool: align_abs(num_person,need, filter=is_candidate, link=persons)
                    - new_indx: if(migrant_pool, indx, new_indx)
                    - indx: indx+1

In the next step I need to randomly distribute the households over the municipalities within each group of municipalities (indx)
so in stead of field "new_indx" which goes from 1 to 47, I need a id of the municipalities in each group indx.
I have an entity "residency" with the field "indx".

Can anyone give me a clue on how to randomly assign a munipality id belonging to each new_indx to the households?

Hope my question was somewhat clear....

thanks in advance,
Ingrid

Gaëtan de Menten

unread,
Feb 19, 2019, 8:20:37 AM2/19/19
to liam2...@googlegroups.com

Hi Ingrid,

 

Assuming your municipalities ids range from 0 to N-1 (where N is the total number of municipalities) and each group of municipalities corresponds to a contiguous range of ids, this is not too hard:

 

                # define arrays which represent the first and "last" ID for each group

                # these could be defined as global arrays instead to load that information from an external file

                # In the example below, group 0 will "generate" ids between 0 and 9, group 1 will have ids 10 to 24, etc…

                - MUNGROUP_FIRSTID: array([ 0, 10, 25])

                - MUNGROUP_LASTID:  array([ 9, 24, 29])

               

                # if you prefer, you could just define a MUNGROUP_LENGTHS global array and compute FIRST and LAST ids automatically:

                - MUNGROUP_LENGTHS: array([ 10, 15, 5])

                - MUNGROUP_LASTID: MUNGROUP_LENGTHS.cumsum() - 1

                - MUNGROUP_FIRSTID: MUNGROUP_LASTID - MUNGROUP_LENGTHS + 1

               

                # sadly, randint, does not support bounds which are different per-individual, so this does not work:

                # - mun_id: randint(first_id, last_id + 1)

                # luckily uniform does, so we can emulate that:

                - mun_id: trunc(uniform(MUNGROUP_FIRSTID[group_id], MUNGROUP_LASTID[group_id] + 1))

 

                - show(dump(group_id, MUNGROUP_FIRSTID[group_id], MUNGROUP_LASTID[group_id], mun_id))

 

If your municipalities groups do not represent contiguous range of ids, this is also possible but trickier…

 

Hope it helps,

 

Gaëtan

 

--
You received this message because you are subscribed to the Google Groups "liam2-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liam2-users...@googlegroups.com.
To post to this group, send email to liam2...@googlegroups.com.
Visit this group at https://groups.google.com/group/liam2-users.



Disclaimer: This e-mail may contain confidential information which is intended only for the use of the recipient(s) named above.
If you have received this communication in error, please notify the sender immediately and delete this e-mail from your system.
Please note that e-mail messages cannot be considered as official information from the Federal Planning Bureau.

Ingrid Schockaert

unread,
Feb 28, 2019, 7:30:51 AM2/28/19
to liam2-users
Dear Gaetan, 

My municipalities do not range from 0 to N-1. If necessary, I could change the id's in that sense, but arranging that each group of municipalities corresponds to contiguous range of ids is harder since I would like to use the same trick for internal and external migration and groups will not be the same. 

Therefore, I would be much interested in your trickier sollution without contiguous range of ids...

Regards,
Ingrid

Gaëtan de Menten

unread,
Mar 18, 2019, 4:17:58 PM3/18/19
to liam2...@googlegroups.com

Dear Ingrid,

 

Sorry, but I realize now I never answered this message. As you may know, the Federal Planning Bureau is extremely busy these days to evaluate the consequences of political parties programs for the next Belgian elections. I will not have time to do anything not related to that project before mid May. And at that point I will have a lot of catching up to do for all the projects that I have put aside for several months now (such as LIAM2). In short, I am truly sorry but I will probably only have time to throw together some example code to answer this email properly somewhere in late May or June.

 

Sorry again,

Reply all
Reply to author
Forward
0 new messages