* so set max lags = 150 to cover both (will also mean 2 weekends)
localmax_lag=150
localmidweektl0xline(3570,lstyle(refline))
* the labels don't seem to show up?
localmidweektll0text(350.5"This time tomorrow",place(w))text(700.5"This time next weekend",place(e))// weekend
localmidweektl0xline(3672,lstyle(refline))
localmidweektl1xline(3570105,lstyle(refline))
localmidweektll0text(360"This time tomorrow")text(720"This time next weekend")// weekend
* the labels don't seem to show up?
localmidweektll1text(350"This time tomorrow",place(w))text(700"This time the day after tomorrow",place(w))text(1050"This time next week",place(w))// midweek
localmidweektl1xline(3672108,lstyle(refline))
localmidweektll1text(360"This time tomorrow")text(720"This time the day after tomorrow")text(1080"This time next week")// midweek
* this creates a big list of all IDs so we can loop over it - takes a while
* could just start from min & loop to max - but would then be testing for non-existent households
qui:levelsofID,local(ids)
localecont1"In work"
localecont1"In work"
localecont2"Unemployed"
localecont2"Unemployed"
localecont3"Retired"
localecont3"Retired"
localecont4"Caring for relative or family"
localecont4"Caring for relative or family"
* filter for
gens_hour=hh(s_halfhour)
* this creates a big list of all IDs so we can loop over it - takes a while
* could just start from min & loop to max - but would then be testing for non-existent households
* qui: levelsof ID, local(ids)
* for testing
localids"1002 1003 1004"
foreachmoflocalmidweek{
foreachmoflocalmidweek{
di"****************"
di"****************"
di"* Calculating ARs for midweek = `m'"
di"* Calculating ARs for midweek = `m' (`midweekt`m'') "
foreachidoflocalids{
foreachidoflocalids{
di"* -> ID = `id'"
di"* -> ID = `id'"
preserve
preserve
keepifID==`id'&midweek==`m'&ds_halfhour>=12&ds_halfhour<=48// 06:00 - 24:00 -> 36 hour day
* take out 00:00 - 06:00 as repeat cycle of sleep will swamp other cycles
* qui: su ds_halfhour
keepifID==`id'&midweek==`m'&s_hour>6
* check
* need to fool ac into thinking these observations are continuous
* di "Halfhours: `r(min)' - `r(max)'"
qui:suID
* skip over if fails due to lack of hubid
qui:egenlag=fill(1(1)`r(N)')
capturenoisily{
tssetlag
* use s_datetime so ac knows what is missing
* do this here so local is set to the unique valuye for this hh
qui:tssets_datetime
qui:levelsofba_nchildren,local(nch)
* do this here so local is set to the unique valuye for this hh
qui:levelsofba_nadults,local(ba_nadults)
qui:levelsofba_nchildren,local(nch)
qui:levelsofba_empl,local(econ)
qui:levelsofba_nadults,local(ba_nadults)
qui:sus_hour
qui:levelsofba_empl,local(econ)
di"Halfhours: `r(min)' - `r(max)' for ID: `id' (`midweekt`m'', N = `ba_nadults' adults, `nch' children, respondent: `econt`econ'')"