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

Re: st: Difference between dates


From   "Svend Juul" <[email protected]>
To   <[email protected]>
Subject   Re: st: Difference between dates
Date   Mon, 25 Jul 2005 16:22:40 +0200

Jose,

You want to calculate the distance in days between a date and the date
in the previous record. See [U] 16.7 Explicit subscripting (Stata 8
User's Guide; it is [U] 13.7 in Stata 9):

clear
input year month day x1 x2
1979   8   23   0  1
1980   5   23   1  1
1980   6    6   0  0
1981   1    2   1  0
1981   2   20   1  1
end

generate date=mdy(month,day,year)
format date %d
generate nday=date - date[_n-1]
list

     +-------------------------------------------------+
     | year   month   day   x1   x2        date   nday |
     |-------------------------------------------------|
  1. | 1979       8    23    0    1   23aug1979      . |
  2. | 1980       5    23    1    1   23may1980    274 |
  3. | 1980       6     6    0    0   06jun1980     14 |
  4. | 1981       1     2    1    0   02jan1981    210 |
  5. | 1981       2    20    1    1   20feb1981     49 |
     +-------------------------------------------------+


Hope this helps,

Svend 

__________________________________________

Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000  Aarhus C, Denmark
Phone: +45 8942 6090
Home:  +45 8693 7796
Email: [email protected]
__________________________________________ 

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index