Hi Everybody!
I have two variables that measure when a person checked into a facility and when they left again (see data example). As far as I know, the timestamps are already in a format, in which Stata can recognize it as a date and time. For example in the data editor it just says "25mar2022 22:00:00" and so forth. All timestamps are between 24th of March 2022, 12:00 and 27th of March 2022, 9:00.
I would now like to calculate a variable that indicates, whether the people's stay entailed at least one night. In other words, did they stay at the facility between 10PM and 6 AM at least once?
I find working with time variables in Stata very confusing. Can anybody help me with that?
Thanks a lot!
I have two variables that measure when a person checked into a facility and when they left again (see data example). As far as I know, the timestamps are already in a format, in which Stata can recognize it as a date and time. For example in the data editor it just says "25mar2022 22:00:00" and so forth. All timestamps are between 24th of March 2022, 12:00 and 27th of March 2022, 9:00.
I would now like to calculate a variable that indicates, whether the people's stay entailed at least one night. In other words, did they stay at the facility between 10PM and 6 AM at least once?
I find working with time variables in Stata very confusing. Can anybody help me with that?
Thanks a lot!
Code:
* Example generated by -dataex-. For more info, type help dataex clear input double(trial_start trial_end) 1.9638648e+12 1963915948000 1.9637532e+12 1963836405999.9998 1.9638576e+12 1963906080000.0002 1.963926e+12 1963980095000 1.963926e+12 1963983385000.0002 1.9639368e+12 1963996583999.9998 1.963854e+12 1963939665000 1.963782e+12 1963841815000 1.963926e+12 1963996749000 1.9638576e+12 1963914894000.0002 1.963818e+12 1963901958999.9998 1.9638468e+12 1963927559000.0002 1.9638936e+12 1963997112000 1.9638144e+12 1963981392000 1.9637784e+12 1963830336000 1.9637784e+12 1963838773000 1.9637676e+12 1963820090000 1.9638432e+12 1963933670000 1.9637712e+12 1963821229000.0002 1.9639224e+12 1963986526000.0002 1.9638072e+12 1963914968000.0002 1.9638432e+12 1963928894000 1.9637784e+12 1963822947000 1.9638e+12 1963863196000.0002 1.9638432e+12 1963933447000 1.9638936e+12 1963927282000.0002 1.9637748e+12 1963826766000 1.9637676e+12 1963812671000 1.9638612e+12 1963919220000 1.963854e+12 1963918831000.0002 1.9637568e+12 1963777575999.9998 1.9638216e+12 1963950069000 1.9639044e+12 1963987150000.0002 1.9637676e+12 1963818615000 1.9639044e+12 1963987609000 1.9638648e+12 1963914942000 1.9637496e+12 1963823218000 1.9638504e+12 1963889824000 1.9639044e+12 1963928166999.9998 1.9638468e+12 1963912961999.9998 1.9638072e+12 1963919009999.9998 1.9638252e+12 1963998072000 1.9637748e+12 1963823719000 1.9639368e+12 1963990991000 1.963872e+12 1963937086000 1.9638684e+12 1963934661000 1.9637676e+12 1963820528000 1.9638072e+12 1963830564000 1.9638684e+12 1963933904000 1.9638036e+12 1963950656000 1.9638108e+12 1963895296000 1.9637604e+12 1963828394000 1.9638612e+12 1963926777999.9998 1.963836e+12 1963947946000 1.9637676e+12 1963814405000.0002 1.9637496e+12 1963831805000 1.9637496e+12 1963824369000 1.963746e+12 1963826694000 1.9639044e+12 1963997061000 1.9637568e+12 1963834618000 1.9637676e+12 1963808707999.9998 1.9638576e+12 1963912725000 1.9637676e+12 1963819920000 1.9638396e+12 1963857401000 1.9638288e+12 1963907089000 1.9637604e+12 1963827073000 1.9638288e+12 1963902836000 1.9637748e+12 1963831453000 1.9639224e+12 1963997546000 1.9639188e+12 1963991358000 1.9637568e+12 1963908154999.9998 1.9638396e+12 1963913054000 1.9638432e+12 1963949329000 1.9638972e+12 1963980346000 1.9637748e+12 1963824277000 1.9638396e+12 1963953405000 1.9638252e+12 1963911541000 1.9638216e+12 1963906301999.9998 1.9637496e+12 1963905843000 1.963764e+12 1963822229000 1.9637676e+12 1963816929000.0002 1.963746e+12 1963850093000 1.9638396e+12 1963850896000 1.9638036e+12 1963923184000 1.9637676e+12 1963818196999.9998 1.9639224e+12 1963997726000 1.9637568e+12 1963850452000 1.9637712e+12 1963850925000.0002 1.9637676e+12 1963819804000 1.963746e+12 1963825150000.0002 1.96389e+12 1963928469000 1.9638432e+12 1963928252000 1.9638468e+12 1963894875000 1.9637712e+12 1963863554000 1.9638324e+12 1963902990000 1.96389e+12 1963994106000 1.9638684e+12 1963938808000 1.9639224e+12 1963998491999.9998 1.9639224e+12 1963986056999.9998 1.9637784e+12 1963825314000.0002 end format %tc trial_start format %tc trial_end

Comment