help for anythingtodate

Convert all types of date variables to Stata date variables

anythingtodate
varlist
[,
Keepvarlists
Format(string asis)
Reference(integer 19000000)
]

Description

The command anythingtodate converts date variables entered as strings or long number to Stata date variables. Change dates recognized as numbers in Stata to date format.

Options

Keepvarlists If you don't want to rewrite the original variables, it is an option to copy and save the original variables.

By specifying the date format here, you can specify the display format after conversion of the Stata dates.

Reference(integer 19000000) The default is 19000000, but this number can be changed. If the variable has a number that is greater than the specified number, this date variable is considered to be displayed as a long number.

Examples

Set up
. clear all
Enter various types of data data into Stata
. input str8 typestr long typelnum noformatdate
1. "20170101" 20170101 20820
2. "20180320" 20180320 21263
3. "20200202" 20200202 21947
4. end

list
des
anythingtodate typestr typelnum noformatdate, k

list
des

anythingtodate typestr_original, f(%tdMonth_nn,_CCYY)
list
des

Author

Nobuaki Michihata, Department of Health Services Research, Graduate School of Medicine

The University of Tokyo

Please email gha10771+stata@gmail.com if you encounter problems with this program