Statalist


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

Re: st: converting dates from Excel .csv file


From   "Salah Mahmud" <salah.mahmud@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: converting dates from Excel .csv file
Date   Sun, 24 Aug 2008 10:45:39 -0500

Following the above, you could use year(), month(), day() to extract
the date components if that is your aim.


On Sun, Aug 24, 2008 at 10:43 AM, Salah Mahmud <salah.mahmud@gmail.com> wrote:
> Hi Michael,
>
> Have you tried the date function?
>
> input str12 date
>       "12/12/08"
>       "12/02/08"
>       "4/14/08"
>       "4/04/08"
> end
> gen d=date(date, "MDY", 2010)
> format d %d
> list
>
> Tested using Stata 10.1
>
> /salah
>
>
>
> On Sat, Aug 23, 2008 at 9:14 PM, Michael McCulloch <mm@pinest.org> wrote:
>> Hello,
>> I have dates in an Excel *.csv file as:
>>
>>        date
>>        12/12/08
>>        12/02/08
>>        04/14/08
>>        04/04/08
>>
>> 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?
>>
>>
>> --
>>
>> Best wishes,
>> Michael McCulloch
>>
>>
>>
>> Pine Street Foundation
>> 124 Pine St., San Anselmo, CA 94960-2674
>> Tel:    (415) 407-1357
>> Fax:    (415) 485-1065
>> mcculloch@pinestreetfoundation.org
>> www.pinestreetfoundation.org
>>
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/statalist/faq
>> *   http://www.ats.ucla.edu/stat/stata/
>>
>
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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