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

Re: st: importing and converting dates from Excel .csv file

From   Phil Schumm <[email protected]>
To   [email protected]
Subject   Re: st: importing and converting dates from Excel .csv file
Date   Wed, 27 Aug 2008 16:32:38 -0500

On Aug 27, 2008, at 3:42 PM, Michael McCulloch wrote:
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?

I'm not sure I understand correctly, but if all you want to do is to translate the variable into a Stata date, none of this is necessary. For example:

. di %td date("12/2/08","MD19Y")

-- Phil

* For searches and help try:

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