Statalist


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

Re: st: date(s1,s2) leads to no values


From   "Fabian Brenner" <Fabian.Brenner@gmx.de>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: date(s1,s2) leads to no values
Date   Wed, 24 Sep 2008 22:59:40 +0200

Thank you for your help,

I tried to use Eva's solution. The first step (replace date = substr(date,1,4) + "/" + substr(date,5,2) + "/" + substr(date,7,2)) does exactly what it should do but begin=date(date,"YMD") only produces missings again. (My dates have zeros filled in where necessary). I don't know why this happens.

But Richard's solution did work.
-todate statpers_as_string, gen(num_date) p(yyyymmdd)-
-tostring num_date-

Regards,
Fabian


-------- Original-Nachricht --------
> Datum: Wed, 24 Sep 2008 20:43:29 +0100
> Von: "Eva Poen" <eva.poen@gmail.com>
> An: statalist@hsphsun2.harvard.edu
> Betreff: Re: st: date(s1,s2) leads to no values

> Alternatively, you can do
> 
> replace date = substr(date,1,4) + "/" + substr(date,5,2) + "/" +
> substr(date,7,2)
> 
> followed by your original -generate- command. Prior to version 10,
> Stata wants some form of separator when using the date() function.
> 
> (This assumes that your dates have zeros filled in where necessary,
> e.g. "19860701"),
> 
> HTH,
> Eva
> 
> 
> 2008/9/24 Richard Goldstein <richgold@ix.netcom.com>:
> > If I remember correctly, version 8 could not deal with run-together
> dates
> > like this
> >
> > download the -todate- file from ssc (when connected to the internet,
> type
> > -ssc install todate- on the Stata command line)
> >
> > Rich
> >
> > Fabian Brenner wrote:
> >>
> >> Dear all:
> >>
> >> variable "date" is str8   %9s (one example:19861230). I would like to
> use
> >> gen begin=date(date,"YMD") to get elapsed dates but stata does not put
> any
> >> values in variable "begin" (only missings).
> >>
> >> Hope someone can help me. I use stata 8.
> >> Fabian
> *
> *   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/

-- 
GMX Kostenlose Spiele: Einfach online spielen und Spaß haben mit Pastry Passion!
http://games.entertainment.gmx.net/de/entertainment/games/free/puzzle/6169196
*
*   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