Hello, I have a data set for apartments with these variables: Building_id: ID for the building that the apartment is located in. Apartment_id: ID for the apartment itself. I would like to generate a variable, Group_id, that groups the apartments together in groups. These groups have to include a minimum of 12 apartments and these apartments need the same building_id. So, if there are 23 apartments with the same building_id they would simply be in one group, because there are not enough apartments for 2 groups of 12. If there are 24 apartments with the same building_id, they would be in two groups of 12. If there are 25 apartments with the same building_id, they would be in two groups of 12 and 13. Another example: if there are 100 apartments in the same building (with the same building_id), I want the first 12 to be grouped with one Group_id, 13-24 to be grouped with another Group_id, 25-36 with a third Group_id,..., and then the last apartments from 84-100 to be grouped together with the same Group_id. The last group includes 16 apartments (larger than 12), but if we grouped 84-96 together, then the last 4 apartments would be too few to be in a group, because of the 12 minimum rule. My data set include a lot of apartments with a lot of different building-id's, so I am hoping for a code that does this grouping automatically. I hope this makes sense - please ask away if it doesn't. Hoping someone can help :-).
... View more