I have dates in a CSV, and this is the first time I am running into this problem that when converting the dates from the CSV to Stata I am getting missing values. I usually use:
I have a variable from Excel, ‘xdate’
gen stata_date = date(xdate, “mdy”)
This usually works, but for this data set I am getting all missing values.
In Excel the format category is Date and the Type is *3/14/2001. Weirdly, when I change the format to custom mm/dd/yyyy (when I go to custom now it is on m/d/yyyy) and then rerun my .DO the dates translate perfectly, but when I restart Stata and run the .DO without this manual change I get all missing values.
Any ideas?
Added: 2012-10-13––Another Stata user pointed out that “mdy” in the date() function should be “MDY”.
If fixing this error does not solve the problem, examine the CSV file to find out what you are feeding Stata:
• -split- will complain if there are any non-numeric characters other than “/” in the string date. To see what they are, I recommend Nick Cox’s -charlist- command (from SSC).
• xdate1, xdate2, and xdate3 should be month, day, and year. You can inspect them with -tab- and -codebook-. After fixing any errors, a fool-proof way of creating the date is: