I have a household indicator #hhd#, month and day indicators #month# #day# and three dummy variables #mark_1# #mark_2# #mark_3#
a household starts with all dummy variables at 0 and each dummy can be activated one at a time. Once a dummy changes from 0 to 1, it stays 1 throughout ever subsequent day for that household. #mark_1# must be activated before #mark_2#, #mark_2# must be activated before #mark_3#.
The problem I am having is that no more than one dummy ought to be activated in any given month. So for example both #mark_1# and #mark_2# cannot both be 0 on January 1st and both be 1 on January 31st however they can both be 1 on February 1st.
At the moment, I have some households where more than one dummy variable is being turned from 0 to 1 in the same month.
For example
The desired outcome would be something such as this
I have approximately 200K households so looping over households is not ideal but I am wondering if there is a way that I can resolve this issue. If some sort of loop is possible, then it would be okay.
Thank you
a household starts with all dummy variables at 0 and each dummy can be activated one at a time. Once a dummy changes from 0 to 1, it stays 1 throughout ever subsequent day for that household. #mark_1# must be activated before #mark_2#, #mark_2# must be activated before #mark_3#.
The problem I am having is that no more than one dummy ought to be activated in any given month. So for example both #mark_1# and #mark_2# cannot both be 0 on January 1st and both be 1 on January 31st however they can both be 1 on February 1st.
At the moment, I have some households where more than one dummy variable is being turned from 0 to 1 in the same month.
For example
Code:
ssc install datex input long hhd float month float day double mark_1 double mark_2 mark_3 1 1 1 0 0 0 1 1 2 0 0 0 1 1 3 0 0 0 1 1 4 0 0 0 1 1 5 0 0 0 1 1 6 0 0 0 1 1 7 0 0 0 1 1 8 0 0 0 1 1 9 0 0 0 1 1 10 1 0 0 1 1 11 1 0 0 1 1 12 1 0 0 1 1 13 1 0 0 1 1 14 1 0 0 1 1 15 1 0 0 1 1 16 1 0 0 1 1 17 1 0 0 1 1 18 1 0 0 1 1 19 1 0 0 1 1 20 1 1 0 1 1 21 1 1 0 1 1 22 1 1 0 1 1 23 1 1 0 1 1 24 1 1 0 1 1 25 1 1 0 1 1 26 1 1 0 1 1 27 1 1 0 1 1 28 1 1 0 1 1 29 1 1 0 1 1 30 1 1 0 1 1 31 1 1 0 1 2 1 1 1 0 1 2 2 1 1 0 1 2 3 1 1 0 1 2 4 1 1 0 1 2 5 1 1 0 1 2 6 1 1 0 1 2 7 1 1 0 1 2 8 1 1 0 1 2 9 1 1 0 1 2 10 1 1 0 1 2 11 1 1 0 1 2 12 1 1 0 1 2 13 1 1 0 1 2 14 1 1 0 1 2 15 1 1 0 1 2 16 1 1 0 1 2 17 1 1 1 1 2 18 1 1 1 1 2 19 1 1 1 1 2 20 1 1 1 1 2 21 1 1 1 1 2 22 1 1 1 1 2 23 1 1 1 1 2 24 1 1 1 1 2 25 1 1 1 1 2 26 1 1 1 1 2 27 1 1 1 1 2 28 1 1 1 1 3 1 1 1 1 1 3 2 1 1 1 1 3 3 1 1 1 1 3 4 1 1 1 1 3 5 1 1 1 1 3 6 1 1 1 1 3 7 1 1 1 1 3 8 1 1 1 1 3 9 1 1 1 1 3 10 1 1 1 1 3 11 1 1 1 1 3 12 1 1 1 1 3 13 1 1 1 1 3 14 1 1 1 1 3 15 1 1 1 1 3 16 1 1 1 1 3 17 1 1 1 1 3 18 1 1 1 1 3 19 1 1 1 1 3 20 1 1 1 1 3 21 1 1 1 1 3 22 1 1 1 1 3 23 1 1 1 1 3 24 1 1 1 1 3 25 1 1 1 1 3 26 1 1 1 1 3 27 1 1 1 1 3 28 1 1 1 1 3 29 1 1 1 1 3 30 1 1 1 1 3 31 1 1 1 end
Code:
input long hhd float month float day double mark_1 double mark_2 mark_3 1 1 1 0 0 0 1 1 2 0 0 0 1 1 3 0 0 0 1 1 4 0 0 0 1 1 5 0 0 0 1 1 6 0 0 0 1 1 7 0 0 0 1 1 8 0 0 0 1 1 9 0 0 0 1 1 10 1 0 0 1 1 11 1 0 0 1 1 12 1 0 0 1 1 13 1 0 0 1 1 14 1 0 0 1 1 15 1 0 0 1 1 16 1 0 0 1 1 17 1 0 0 1 1 18 1 0 0 1 1 19 1 0 0 1 1 20 1 0 0 1 1 21 1 0 0 1 1 22 1 0 0 1 1 23 1 0 0 1 1 24 1 0 0 1 1 25 1 0 0 1 1 26 1 0 0 1 1 27 1 0 0 1 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