Hi I am new to this site so sorry if this is a very silly question or my problem is not well explained! I am trying to work with dates and can't find the answer in the documentation/other forums.
I want to calculate age using two dates.
I am using as an example code:
. generate mat_age_birth = age(mat_birth_date, child_birthdate)
However using my current dataset this code generates a new variable with all missing values. i.e. no error code but it says missing values generated.
I think perhaps the issue is the way that the dates I am using are stored?? They are stored as double variables, format %tcDD-MON-CCYY
I have tried to change the variable to either a string but with no success. I have tried to using "tostring", and "recast" to try to generate string variables - it comes back with "cannot be converted reversibly" so I think perhaps these are not appropriate for this particular issue?
My question is
1. can I calculate with dates while they are stored as "double" and if so how do I modify the above code to give me valid results
2. if not, is it best to convert to string, and what is the code I would need to convert a double variable to string
Thanks in advance and apologies if this is a silly question!
I want to calculate age using two dates.
I am using as an example code:
. generate mat_age_birth = age(mat_birth_date, child_birthdate)
However using my current dataset this code generates a new variable with all missing values. i.e. no error code but it says missing values generated.
I think perhaps the issue is the way that the dates I am using are stored?? They are stored as double variables, format %tcDD-MON-CCYY
I have tried to change the variable to either a string but with no success. I have tried to using "tostring", and "recast" to try to generate string variables - it comes back with "cannot be converted reversibly" so I think perhaps these are not appropriate for this particular issue?
My question is
1. can I calculate with dates while they are stored as "double" and if so how do I modify the above code to give me valid results
2. if not, is it best to convert to string, and what is the code I would need to convert a double variable to string
Thanks in advance and apologies if this is a silly question!

Comment