[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: converting dates from Excel .csv file

From   Michael McCulloch <>
To   Statalist <>
Subject   Re: st: converting dates from Excel .csv file
Date   Thu, 28 Aug 2008 07:12:58 -0700

On 8/23 I submitted a question: > I have dates in an Excel *.csv file as:

 I wrote the following code to convert to Stata date:
        gen str date_year = substr(date, -2,.)
        gen str date_month = substr(date, 1, 2)
        gen str date_day = substr(date, 4, 2)
        destring  date_year date_month date_day, replace
        list date date_month date_day date_year

 However, when I import the *.csv file, the leading zeroes are dropped
 from months 1-9.
 Is there a way to solve this in Stata, without having to create
 separate columns for m, d, and y in Excel?
On 8/24 Salah responded with the following advice, which unfortunately is not successful (error msg: 60 missing values generated). I note that Salah's code which he wrote in Stata 10.1 worked for him, but not for me; I'm using 9.2. Any advice?

Have you tried the date function?

input str12 date
gen d=date(date, "MDY", 2010)
format d %d

Tested using Stata 10.1


* For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index