I have a date variable stored as numeric stata date variable as type double which holds day, month, year, time (admission_date) which is displaced as DD-MM-YYYY H:M:S with the %tc format (eg displaced as 12aug2021 00:00:00. I wish to generate a new variable that holds only the year (admission_year). The new variable for year only (admission_year) is generated with all missing values, although the existing variable (admission_date) has no missing values. I have tried the code below and all generate the new variable with all values missing.
gen admission_yr = year(admission_date)
gen double admission_yr = year(admission_date)
gen admission_yr = dofy(admission_date)
Please advise what I am doing wrong.
gen admission_yr = year(admission_date)
gen double admission_yr = year(admission_date)
gen admission_yr = dofy(admission_date)
Please advise what I am doing wrong.
Comment