Hey guys,
Let me preface by saying while I am new to Stata I have tried extensively to figure this out on my own, so my apologies if this is a beginner question. Alright so here it is:
I have a dataset that includes a string variable that describes an employees shift in the following format: " 03jul2014 2 p.m. to 10 p.m." or even "16may2015 10 p.m. to noon" I've been tasked with determining whether two separate variables (these are in the correct %tc format already) fall within the shift length. However, as has been shown in the above example are not in the correct format. So I have two problems.
1. How can I convert the shift variables into a %tc variable? I think the best way to accomplish this would be to split the variables into two different variables. This would require destringing the variable and maybe creating some sort of an array split by spaces that I can manipulate into two different variable sets. However, I'm ill-equipped on how to accomplish this.
2. Because the shifts sometimes go from one day to another I need to adjust the variable for that. I think this would be an IF THEN esque argument that would add +1 to the date dependant on whether the shift goes from pm to am. (or pm to noon). However, this could create a problem if the date is the last day of the month.
I'm still in the process of learning the software, so any sort of advice or direction for either of these problems would be greatly appreciated.
Thanks!
Let me preface by saying while I am new to Stata I have tried extensively to figure this out on my own, so my apologies if this is a beginner question. Alright so here it is:
I have a dataset that includes a string variable that describes an employees shift in the following format: " 03jul2014 2 p.m. to 10 p.m." or even "16may2015 10 p.m. to noon" I've been tasked with determining whether two separate variables (these are in the correct %tc format already) fall within the shift length. However, as has been shown in the above example are not in the correct format. So I have two problems.
1. How can I convert the shift variables into a %tc variable? I think the best way to accomplish this would be to split the variables into two different variables. This would require destringing the variable and maybe creating some sort of an array split by spaces that I can manipulate into two different variable sets. However, I'm ill-equipped on how to accomplish this.
2. Because the shifts sometimes go from one day to another I need to adjust the variable for that. I think this would be an IF THEN esque argument that would add +1 to the date dependant on whether the shift goes from pm to am. (or pm to noon). However, this could create a problem if the date is the last day of the month.
I'm still in the process of learning the software, so any sort of advice or direction for either of these problems would be greatly appreciated.
Thanks!

Comment