Hi everyone,
Suppose that there is data with civil ID and date of birth, many times you will find values for date of birth are missing, in this case, it would be useful to obtain the date of birth from the civil ID and verify the data and double check others.
Lets say the civil ID has 12 digits and look something like this:
310051209216
265102508032
The first digit to the left indicate the century and the second and thirds digits to the left indicate the year so, 310 means that person born in 2010 and 265 means that person born in 1965. The fourth and fifth digits from the left indicate the month and the sixth and seventh digits from left indicate the days. As such the first person according to the civil ID born on 12 of May 2010, while the second person born on 25 October 1965.
Is there a command to extract those specific digits and convert them into dates like shown above?
I tried:
But it will be problematic to convert those three variables into one variable representing as a date. Is there any other more elegant way to do that?
Thanks!
Suppose that there is data with civil ID and date of birth, many times you will find values for date of birth are missing, in this case, it would be useful to obtain the date of birth from the civil ID and verify the data and double check others.
Lets say the civil ID has 12 digits and look something like this:
310051209216
265102508032
The first digit to the left indicate the century and the second and thirds digits to the left indicate the year so, 310 means that person born in 2010 and 265 means that person born in 1965. The fourth and fifth digits from the left indicate the month and the sixth and seventh digits from left indicate the days. As such the first person according to the civil ID born on 12 of May 2010, while the second person born on 25 October 1965.
Is there a command to extract those specific digits and convert them into dates like shown above?
I tried:
Code:
gen yrs = real(substr( var , -12, 3)) gen months = real(substr( var , -9, 2)) gen days = real(substr( var , -7, 2))
Thanks!
Comment