[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
RE: st: Re: How To get 4-digit Year Number
-date()- is for daily dates. Thus you must
supply day, month and year.
Think about this way: you are Stata. I
tell you that my birthday is in March 2006.
But I don't tell you which day of the month
it is. You do not have enough information
to compute a daily date. -date- similarly
take partial dates such as those in "my"
Sometimes, if people just know month
and year, say "11/37", they impute a day,
date("15/" + "11/37", "dmy", 2010)
is legal, as would be
date("15/" + monthyear, "dmy", 2010)
if -monthyear- were a variable.
Also check out -split-, -substr()-, -strpos()-.
Run-together dates are discussed by StataCorp at
FAQ . Handling date information when numbers are in a continuous sequence
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . D. Reichel
2/03 How do I convert date variables into Stata elapsed
dates when the numbers run together, like 4151999?
That points to a user-written program -todate- on SSC. I am not sure
why StataCorp is reluctant to add functions for run-together dates,
unless it is concern that the problem can be ill-posed, e.g. "11106".
> By the way, what if the dates are in other forms, such as 11/1937, or
> 23101988, etc. ?
> I think of something like :
> generate qyr = date(dateinc, "mdy" | "my" | "string-here" | etc. )
> to read and then do other steps. But I can't make it work, at
> least with format "my" ?
> Even when using qyr = monthly(dateinc) if (some specific
> conditions), I
> can't get the 4-digit year number from format "my".
* For searches and help try: