Hi all statalists!
In my data, I have the dates of exams (test_date) and the time they started (start_hour).
test_date is in DMY format. While start_hour is in a weird format (integer), for example, start_hour == 900 says that the exam started at 9:00 a.m. or 09:00 in 24-hour format, and start_hour == 1430 indicates that the exam started at 2:30 p.m. or 14:30 in 24-hour format.
I attach a sample of my data below:
I would like to generate two new variables:
In my data, I have the dates of exams (test_date) and the time they started (start_hour).
test_date is in DMY format. While start_hour is in a weird format (integer), for example, start_hour == 900 says that the exam started at 9:00 a.m. or 09:00 in 24-hour format, and start_hour == 1430 indicates that the exam started at 2:30 p.m. or 14:30 in 24-hour format.
I attach a sample of my data below:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int(test_date start_hour) 16560 900 16579 1415 16589 1445 16589 1700 16602 1100 16615 900 16618 900 15465 1430 15467 900 15467 1100 end format %td test_date
I would like to generate two new variables:
- time_hour, which takes the values of start_hour and converts them into 24-hour format. For example, when start_hour == 1430, time_hour == 14:30.
- date_time, which consists of the date and the time of the exam. For instance, for the first row (test_date == 04may2005 and start_hour == 900), I want to see something like 04 May 2005, 09:00. I need date_time to be in a format that enables me to calculate the difference between two dates. For example, the difference in days between the first observation and the second observation is 19 and in minutes is 27,675.
Comment