# RE: st: Re: How To get 4-digit Year Number

 From "Nick Cox" To Subject RE: st: Re: How To get 4-digit Year Number Date Fri, 17 Mar 2006 15:06:44 -0000

```-date()- is for daily dates. Thus you must
supply day, month and year.

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"
form.

Sometimes, if people just know month
and year, say "11/37", they impute a day,
say 15.

So

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?
http://www.stata.com/support/faqs/data/dateseq.html

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".

Nick
n.j.cox@durham.ac.uk

Akihito Tokuhara

> 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:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```