Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: generating age using dates


From   martine etienne <[email protected]>
To   [email protected]
Subject   Re: st: generating age using dates
Date   Fri, 17 Dec 2010 10:20:10 -0800 (PST)

thank you very much for the clarity, this command is very clear and makes sense:
di date("31/12/2005", "DMY")
16801

. di %td date("31/12/2005", "DMY")
31dec2005 

but am I using this for each individual date? I have 287 samples. ie..

. di date("01/04/1956", "MDY")
-1458

. di %td date("01/04/1956", "MDY")
04jan1956





----- Original Message ----
From: Nick Cox <[email protected]>
To: "[email protected]" <[email protected]>
Sent: Fri, December 17, 2010 1:00:38 PM
Subject: RE: st: generating age using dates

Bad news which is also good news: That's quite wrong. 

-encode- just maps the ordered dates to integers 1 up. It appears to keep the 
date information because you see value labels which look like dates, but 
underneath it is just integers with negligible chance of ever being what you 
want. 


. encode string_date , gen(num_date)

. l

     +-------------------------+
     | string_d~e     num_date |
     |-------------------------|
  1. | 31/12/2005   31/12/2005 |
  2. | 31/12/2006   31/12/2006 |
  3. | 31/12/2007   31/12/2007 |
  4. | 31/12/2008   31/12/2008 |
  5. | 31/12/2009   31/12/2009 |
     +-------------------------+

. l , nola

     +-----------------------+
     | string_d~e   num_date |
     |-----------------------|
  1. | 31/12/2005          1 |
  2. | 31/12/2006          2 |
  3. | 31/12/2007          3 |
  4. | 31/12/2008          4 |
  5. | 31/12/2009          5 |
     +-----------------------+

So, if you use arithmetic on the numeric variables created they act like dates 
from 1 Jan 1960 up, but that's generally going to be very wrong indeed. 


You need to use specific date functions. -encode- knows nothing about dates. 
Consider -date()-: 


. di date("31/12/2005", "DMY")
16801

. di %td date("31/12/2005", "DMY")
31dec2005


Nick 
[email protected] 

martine etienne

i used the following command:

encode q1_dob, generate (q1_dob2)

From: Nick Cox <[email protected]>

How did you "encode" that? 

martine etienne

the variable q1_dob2 is the only one that I generated from encoding the original 


variable q1_dob which was is in string format:


des q1_dob

              storage  display     value
variable name   type   format      label      variable label
----------------------------------------------------------------------------------------------------------------------



q1_dob          str10  %10s        

all years are four digits, see below:

tab q1_dob

     q1_dob |      Freq.     Percent        Cum.
------------+-----------------------------------
01/04/1956 |          1        0.35        0.35
01/05/1964 |          1        0.35        0.70
01/05/1968 |          1        0.35        1.05
01/06/1956 |          1        0.35        1.39
01/06/1963 |          1        0.35        1.74
01/07/1960 |          1        0.35        2.09
01/10/1975 |          1        0.35        2.44
01/12/1957 |          1        0.35        2.79
      
also, there is only one missing date of birth in the original variable and it is 


coded as 99/99/9999, there
are no missing dates in the survey_date variable.

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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index