<>
" Second, here are the reasons I discovered:
1. Dates were obtained from Excel, in display format mm/dd/yy. -date-
requires they be in mm/dd/yyyy format, where all four year digits are
displayed.
2. I hadn't capitalized the "MDY" specification within -date- argument."
Number 2 is agreed, number 1 is not: You just need to tell Stata what to do
about 2 digit years...
- display %td date("5-12-98", "MD19Y")-
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Michael
McCulloch
Gesendet: Mittwoch, 7. Oktober 2009 19:17
An: [email protected]
Betreff: Re: st: AW: -date- creates missing values
Thanks Martin. Your suggestion to experiment with displaying -date-
helped solve this problem.
What I did was:
. display %td date("5-12-1998", "MDY")
. display %td date("5-12-98", "MDY")
. display %td date("5/12/1998", "MDY")
. display %td date("5/12/98", "MDY")
I've discovered the two reasons my do-file command was creating
missing values.
First, here's the command:
foreach D of varlist d_sample1 ///
d_sample2 ///
{
generate `D'1 = date(`D', "mdy", 2010)
format `D'1 %d
drop `D'
rename `D'1 `D'
}
Second, here are the reasons I discovered:
1. Dates were obtained from Excel, in display format mm/dd/yy. -date-
requires they be in mm/dd/yyyy format, where all four year digits are
displayed.
2. I hadn't capitalized the "MDY" specification within -date- argument.
On Oct 5, 2009, at 1:04 PM, Martin Weiss wrote:
>
> <>
>
> Have you had a look at -help whatsnew9to10-, particularly "What's
> new in
> data management"? And try both versions of this:
>
>
> *************
> di date("102108", "mdy", 2010)
> di date("102108", "MDY", 2010)
> *************
>
>
>
> HTH
> Martin
>
>
> -----Ursprüngliche Nachricht-----
> Von: [email protected]
> [mailto:[email protected]] Im Auftrag von Michael
> McCulloch
> Gesendet: Montag, 5. Oktober 2009 19:25
> An: Statalist Statalist
> Betreff: st: -date- creates missing values
>
> Hello friends,
> I recently moved a do-file from Stata 9 to 10, and the following short
> date program, instead of creating Stata dates, now creates missing
> values. It's supposed to take dates in MM/DD/YY format imported from
> an Excel .csv file, and translating them to Stata date format.
>
> I'd appreciate any pointers/critiques on my method, or what I missed
> in the 9 to 10 upgrade...
>
> *prep date vars, from mm/dd/yy
> foreach D of varlist d_sample1 ///
> d_sample2 ///
> {
> generate `D'1 = date(`D', "mdy", 2010)
> format `D'1 %d
> drop `D'
> rename `D'1 `D'
> }
>
>
> Michael McCulloch, LAc MPH PhD
> Pine Street Foundation
> 124 Pine Street
> San Anselmo, CA 94960-2674
> tel: 415-407-1357
> fax: 206-338-2391
> [email protected]
>
>
>
>
>
>
> *
> * 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/
Michael McCulloch, LAc MPH PhD
Pine Street Foundation
124 Pine Street
San Anselmo, CA 94960-2674
tel: 415-407-1357
fax: 206-338-2391
[email protected]
*
* 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/