Hello I have a question. I have one string variable which have 4 characters the first two are the houres a the two second are the minutes How can I Split that variable into to variable one for the houres and other for the minutes?
Thank you for your question. I hope the following example clarifies your query: clear set obs 100 gen time = runiformint(1000, 2400) tostring time, replace gen hour = substr(time, 1, 2) // Extract the first two characters for the hour gen min = substr(time, 3, 2) // Extract the third and fourth characters for the minutes // Convert hour and min to numeric destring hour, replace destring min, replace
good thanks
Hello I have a question. I have one string variable which have 4 characters the first two are the houres a the two second are the minutes How can I Split that variable into to variable one for the houres and other for the minutes?
Thank you for your question. I hope the following example clarifies your query:
clear
set obs 100
gen time = runiformint(1000, 2400)
tostring time, replace
gen hour = substr(time, 1, 2) // Extract the first two characters for the hour
gen min = substr(time, 3, 2) // Extract the third and fourth characters for the minutes
// Convert hour and min to numeric
destring hour, replace
destring min, replace