Hello,
I am using Stata 17 and have ran into a data problem. I have a day-month-year variable which is inconsistently inputted: some dates have a '0' in from of the combination (01012021 for January 1, 2021) and some do not (1012021 for January 1, 2021). As such, I am not confident in using the day and month parts of the date variable, nor do I need them. I am wondering how I can extract the last four digits of this variable (i.e. the year)? I tried to experiment by changing the format (by going to data drop down menu, variable manager, create) to do this, but it does not work (presumably because of the inconsistency in how many numbers the date variable provides across observations). I would like to end up with a four digit year variable only. If anyone has any ideas or suggestions, they are most welcome.
Thank you!
I am using Stata 17 and have ran into a data problem. I have a day-month-year variable which is inconsistently inputted: some dates have a '0' in from of the combination (01012021 for January 1, 2021) and some do not (1012021 for January 1, 2021). As such, I am not confident in using the day and month parts of the date variable, nor do I need them. I am wondering how I can extract the last four digits of this variable (i.e. the year)? I tried to experiment by changing the format (by going to data drop down menu, variable manager, create) to do this, but it does not work (presumably because of the inconsistency in how many numbers the date variable provides across observations). I would like to end up with a four digit year variable only. If anyone has any ideas or suggestions, they are most welcome.
Thank you!
Comment