I have imported an Excel file into Stata containing a string variable with dates in the Month/Day/Year Format, as following:
+--------------------------+
| country Election |
|--------------------------|
1. | New Zealand 11/29/1969 |
2. | New Zealand 11/25/1972 |
3. | New Zealand 11/27/1999 |
4. | New Zealand 11/25/1972 |
5. | New Zealand 09/17/2005 |
+--------------------------+
My intention is to transform the date, so that only the year appears.
I have used gen year = date(Election, "MDY") to create a new date variable with the float type. However, I don't know how to proceed. How could I transform these dates into years only?
help datetimeespecially the section on "SIF-to-SIF conversion" which is what you want to do - convert from "date" to "yearly". I recommend yougeneratea new variable rather thanreplacethe existing variable. - user4690969