Hi,
in my dataset I have the variable "annualreportdate" indicating at what date the report was written/pubished, written as dmmyy. Since it is always published at the first of a month there are not 2 digits for the day.
I now want to get the year in order to merge it to another dataset.
I already generated a string variable containing these information (annualreportdate_string).
But I am not able to now apply these commands:
gen date = date(annualreportdate_string, "DMY")
gen date = date(annualreportdate_string, "DM20Y")
gen year = yofd(annualreportdate)
Can you tell me how I am able to just get the year as variable out of the given date?
Thank you very much for your help.
in my dataset I have the variable "annualreportdate" indicating at what date the report was written/pubished, written as dmmyy. Since it is always published at the first of a month there are not 2 digits for the day.
I now want to get the year in order to merge it to another dataset.
I already generated a string variable containing these information (annualreportdate_string).
But I am not able to now apply these commands:
gen date = date(annualreportdate_string, "DMY")
gen date = date(annualreportdate_string, "DM20Y")
gen year = yofd(annualreportdate)
Can you tell me how I am able to just get the year as variable out of the given date?
Thank you very much for your help.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int annualreportdate str5 annualreportdate_string 10320 "10320" 10319 "10319" 10318 "10318" 10317 "10317" 10316 "10316" end

Comment