Feb 19, 2016 Sorry for being unclear. I have Stata date variables but now the dates (at the precision of a month) need to be taken to another program in the form YYYYMM (year and month).
For instance I need to convert 15apr1985 to 15jan1999 to 15dec2004 to etc. We would like to show you a description here but the site wont allow us. The reason why your new" date" variable is not getting sorted as expected, is because it is essentially a generic numeric variable with a value label attached to each value: Convert odd Stata string variable to date. 0. Changing a numeric to a string variable in Stata. 2.
Stata String Range Cleaning. 0. To convert such dates to Stata dates, use the mdy function. It takes three numeric arguments: the month, day and year to be converted. It takes a single argument (which cannot be a variable name) and converts it to a date on the assumption that the argument is a string containing a date in the format day, month, year.
This matches the Converting string variables with numeric values. One method of converting numbers stored as strings into numerical variables is to use a string function called real that translates numeric values stored as strings into numeric values Stata can recognize as such. The first line of This is an Introduction to data management in Stata; Assumes basic knowledge of Stata; create string variable and convert to date gen date" November 9 2020" gen date1 date (date, " MDY" ) list date1 in 1 5.
To quote the official Stata manual: m: Two commands, date and format, are used to convert a string date into a numeric date. Within these functions you will need to specify how the datetime information is formatted in the string. However, date variables in raw data are often stored as strings. We converted such string dates to numeric dates using date() and clock() functions. Stata stores numeric dates as the number of elapsed days since 01 Jan 1960 for date() and the number of elapsed milliseconds since 01 Jan 1960 00: 00: 00: 000 for clock().
Jan 10, 2013 Introduction to Stata Generating variables using the generate, replace, and label commands Duration: 8: 31.
UCSF GSI 73, 983 views