-------------------------------------------------------------------------------
help for strdate                                                 (Roger Newson)
-------------------------------------------------------------------------------

Replacing string date variables with numeric date variables with the same names

strdate varlist [, s2(string_argument) ycutoff(numeric_argument) format(%format) ]

where string_argument is either a string in quotes or a string variable name, and numeric_argument is either a number or a numeric variable name.

Description

strdate takes, as input, a list of character date variables in varlist, and replaces them with a list of numeric date variables with the same names and variable labels (if any), occupying the same positions in the variable order as the original character date variables. The conversion is carried out using the date function. The user can specify cutoff year (for two-digit years) and date format.

Options

s2(string_argument) is the s2 string argument passed to the date function; see [U] 16.3.3 Date functions. It may be a string in quotes or a string variable name. Its value should be a permutation of d, m and [##]y, eg mdy or dm20y. ##, if specified, indicates a default century for two-digit years. For instance, dm20y interprets "08/06/55" as 8 June, 2055. If s2 is absent, then it is set by default to dmy.

ycutoff(numeric_argument) is the y numeric argument passed to the date function; see [U] 16.3.3 Date functions. It may be a number or a numeric variable name. Its value should be an integer from 1000 to 9998 (but probably 2001 to 2099), specifying the handling of two-digit years. It denotes the largest year to be returned when a two-digit date is encountered. If it is absent, and there is no ## in the s2 option, then dates with a two-digit year are set to missing.

format(%fmt) specifies the format assigned to the new numeric date variables. If absent, it is set to %dD_m_CY.

Remarks

strdate is used when a generic ASCII file created by a spreadsheet, containing date variables, has been input using insheet. The date variables will be input into Stata as string variables. strdate enables the user to convert these to numeric date variables without the trouble of inventing new names, or reordering variables.

Examples

. insheet using "patient2.dat",clear . strdate startdat stopdat . strdate gprfdat gprldat,s("mdy") y(2050) f(%dDmCY)

Also see

Manual: [U] 16.3.3 Date functions, [R] insheet On-line: help for functions, insheet