Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Years to dates


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Years to dates
Date   Tue, 20 Sep 2005 20:25:43 +0100

It is important to understand that 
Stata is not being difficult here, 
as there are two basic requirements 
that have to be met. 

First, there must be scope for daily dates 
to be represented by numeric variables. 
(You _could_ use a string variable, but 
you couldn't do much with it.) 
That requires some convention about origin 
(what is date 0), and most software writers seem 
agreed that some relatively recent origin 
is most practical. That though is bound to 
seem arbitrary. I see that today's date is 
to Stata 16699, which looks a fun number, 
but otherwise doesn't have any meaning for me. 

Second, there must be scope for different 
formats. So, for example, you use examples 
1/1/1998 and 12/31/1998. I guess the first
is fairly clear to most Statalist members 
but I have to work hard at 12/31/1998 because
it is more common locally to use dates 
like 31 December 1998 and astronomers 
and some others would write 1998 December 31, 
which is the only really logical convention! 
And with dates like 5/6/1998 one has to know 
which convention is being used. So, naturally, 
Stata provides a wide range of formats for
you to choose, so no grumbling! 

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

Terra Curtis
 
> Thanks, Sebastian.  I got it to work using your method and 
> then formating
> the new variable:
> 
> format variable1 %dN/D/Y 
> format variable2 %dN/D/Y
> 
> so that it would make sense to the human reader. 
 
Seb Buechte
 
> Terra Curtis asked for an easy way to create a certain date 
> within a known year:
> 
> I think of one way, eventhough I am not very familiar with 
> time-series data,
> I guess it should still work:
> 
> (let the variable "year" be the container of your years than 
> it should work
> the following way:)
> 
> gen variable1=mdy(1,1,year)
> gen variable2=mdy(12,31,year)
> 

*
*   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/



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