Not too bad -- here you go:
. gen date = mdy(month, day, year)
. gen ndays = date - date[_n - 1]
(1 missing value generated)
. l
+---------------------------------------------+
| year month day x1 x2 date ndays |
|---------------------------------------------|
1. | 1979 8 23 0 1 7174 . |
2. | 1980 5 23 1 1 7448 274 |
3. | 1980 6 6 0 0 7462 14 |
4. | 1981 1 2 1 0 7672 210 |
5. | 1981 2 20 1 1 7721 49 |
+---------------------------------------------+
Note that I get a different number of days from you for the last two observations.
Eric
>Hi all,
>Suppose I had data like this:
>
>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
>...
>
>The data set are ordered by day, month, year, and I want to compute the
>difference in days between adjacente rows (nday), so it looks like this:
>
>year month day x1 x2 nday
>1979 8 23 0 1 .
>1980 5 23 1 1 274
>1980 6 6 0 0 14
>1981 1 2 1 0 240
>1981 2 20 1 1 19
>...
>
>Thanks in advance
>jose
>
>*
>* 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/
--
===================================================
Eric G. Wruck
Econalytics
2535 Sherwood Road
Columbus, OH 43209
ph: 614.231.5034
cell: 614.330.8846
eFax: 614.573.6639
eMail: [email protected]
website: http://www.econalytics.com
====================================================
*
* 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/