Hi all,
I want to create a variable Timegroups which uses another variable Time to create categories.
Time is created from variable RideDate (2020/11/02, 13:57:04) using below code:
gen double Time=clock(RideDate, "YMDhms")
format Time %tcHHMM
So although Time appears as e.g. 1023, 1145, or 2234, the non-formatted version is 02nov2020 10:23:15.
I want to create a variable Timegroups which categorises each Time into a group.
Essentially I want times before 0800 to be categorised as 0, everything between 0800 and 2200 to be categorised as 2, and everything above 2200 to be categorised as 3.
I tried with the code
gen Timegroups=.
replace Timegroups=0 if Time < 0800
replace Timegroups=1 if Time>=0800 & Time<=2200
replace Timegroups=2 if Time>2200
But this obviously doesn't work since Time is formatted differently to what I wrote in the code (and I can't figure out a way for Stata to dismiss the date in the non-formatted section so it only considers the hours).
Thank you.
Related Posts with Used formatted variable to categorised new var
nlcom after elastic net?Hi! I have used the user-written cvlasso (Ahrens, A., Hansen, C.B., Schaffer, M.E. 2018. cvlasso: Pr…
Advice on calculating weighted variable by lagged variableDear Statalists, Even though I went through many related discussions and read many papers about thi…
Creating a Panel and Column namesHi, How could get the first row first Column: Germany to become a panel (so to match each observati…
A question on insheetjson - Keep getting "Invalid column name/selector" error message when using -insheetjson-I am trying to get some data from the API of American Community Survey by using insheetjson. But whe…
Did Stata 15 Change Loops?I just updated to Stata 15 and now a code I consistently use is broken. Have I overlooked something …
Subscribe to:
Post Comments (Atom)
0 Response to Used formatted variable to categorised new var
Post a Comment