Hello, I have a question that somewhat builds off my question a couple days ago. I have daily data, with one variable being when someone attends a program.
We are hoping to create a dummy variable with value 1 (otherwise 0) for the six days following if they attended on a Thursday (which is the day they are supposed to attend typically).
So, if someone is a "1" on Thursday, they should be a 1 on the Friday, Saturday, Sunday, Monday, Tuesday, and Wednesday following, and then it resets on the next Thursday.
It's also possible, though rare, for someone to have attended on a day later than Thursday--so if someone's first "1" value is on a Monday, then we'd want their Tuesday and Wednesday to also be a 1 (and then it would still reset on Thursday). Basically, whenever their first "1" is within a Thursday-to-Thursday week, we want to make sure they have 1's for each day following until it resets the following Thursday.
I hope this description makes sense, I know it is a bit of a roundabout issue. I have been trying various bysort and egen combinations with limited success so far. Thank you in advance for the assistance.
We are hoping to create a dummy variable with value 1 (otherwise 0) for the six days following if they attended on a Thursday (which is the day they are supposed to attend typically).
So, if someone is a "1" on Thursday, they should be a 1 on the Friday, Saturday, Sunday, Monday, Tuesday, and Wednesday following, and then it resets on the next Thursday.
It's also possible, though rare, for someone to have attended on a day later than Thursday--so if someone's first "1" value is on a Monday, then we'd want their Tuesday and Wednesday to also be a 1 (and then it would still reset on Thursday). Basically, whenever their first "1" is within a Thursday-to-Thursday week, we want to make sure they have 1's for each day following until it resets the following Thursday.
I hope this description makes sense, I know it is a bit of a roundabout issue. I have been trying various bysort and egen combinations with limited success so far. Thank you in advance for the assistance.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(id date attend week_day) 16324 21923 . 4 16324 21924 0 5 16324 21925 1 6 16324 21926 0 0 16324 21927 1 1 16324 21928 1 2 16324 21929 1 3 16324 21930 1 4 16324 21931 1 5 16324 21932 1 6 16324 21933 1 0 16324 21934 1 1 16324 21935 1 2 16324 21936 1 3 16324 21937 1 4 16324 21938 1 5 16324 21939 1 6 16324 21940 1 0 16324 21941 1 1 16324 21942 1 2 16324 21943 1 3 16324 21944 1 4 16324 21945 0 5 16324 21946 1 6 16324 21947 1 0 16324 21948 1 1 16324 21949 1 2 16324 21950 1 3 16324 21951 1 4 16324 21952 1 5 16324 21953 1 6 16324 21954 1 0 16324 21955 1 1 16324 21956 1 2 16324 21957 1 3 16324 21958 0 4 16324 21959 0 5 16324 21960 0 6 16324 21961 0 0 16324 21962 0 1 16324 21963 0 2 16324 21964 0 3 16324 21965 1 4 16324 21966 1 5 16324 21967 0 6 16324 21968 0 0 16324 21969 1 1 16324 21970 1 2 16324 21971 1 3 16324 21972 1 4 16324 21973 1 5 16324 21974 1 6 16324 21975 1 0 16324 21976 1 1 16324 21977 1 2 16324 21978 1 3 16324 21979 1 4 16324 21980 1 5 16324 21981 1 6 16324 21982 1 0 16324 21983 1 1 16324 21984 0 2 16324 21985 1 3 16324 21986 1 4 16324 21987 . 5 16324 21988 . 6 16324 21989 . 0 16324 21990 . 1 16324 21991 . 2 16324 21992 . 3 16324 21993 . 4 16324 21994 . 5 16324 21995 . 6 16324 21996 . 0 16324 21997 . 1 16324 21998 . 2 16324 21999 . 3 16324 22000 . 4 16324 22001 . 5 16324 22002 . 6 16324 22003 . 0 16324 22004 . 1 16324 22005 . 2 16324 22006 . 3 16324 22007 0 4 16324 22008 0 5 16324 22009 0 6 16324 22010 0 0 16324 22011 0 1 16324 22012 0 2 16324 22013 0 3 16324 22014 0 4 16324 22015 0 5 16324 22016 0 6 16324 22017 0 0 16324 22018 0 1 16324 22019 0 2 16324 22020 0 3 16324 22021 . 4 16324 22022 . 5 end format %tdnn/dd/CCYY date
Comment