st: random date generator

Dear Statalist
I work with Stata 10 (upgrate for Stata 11 is ordered) and I would
appreciate your advices for a "random date generator".
I have panel Data were survivaltime is a dependent variable.
Excerpt from my datastructure:
ID Year survivaltime status "born" date for
status 1 date f. st.2 date f. st.3 deliverydate
1 2000 1098 0 03Jan2000 10jan2003
. . 18jun2009
1 2001 1098 0 03Jan2000 10jan2003
. . 18jun2009
1 2002 1098 0 03Jan2000 10jan2003
. . 18jun2009
1 2003 1098 1 03Jan2000 10jan2003
. . 18jun2009
2 2000 3453 0 04Jan2000 . .
. 18jun2009
2 2001 3453 0 04Jan2000 . .
. 18jun2009
2 2002 3453 0 04Jan2000 . .
. 18jun2009
3 2000 3453 0 04Jan2000 . .
. 18jun2009
3 2001 3453 0 04Jan2000 . .
. 18jun2009
3 2002 3453 3 04Jan2000 . .
. 18jun2009
The variable status has the numbers 0,1,2,3 and they mean 0=pending, and
1,2,3 = "death". If the person "dies" because of reason 1 I have
information in the colum "date for status 1" and date f.st.2 and date f.
st.3 are missing. The same system is for status 2 and 3. If the person
does not die, the status in the last observed year is 0 and i have no
dates.
The survivaltime I computed with:
replace survivaltime=date for status 1-"born" if (date for status 1!=. &
status!=.) etc
and for the pendings:
replace survivaltime=deliverydate-"born" if (date for status 1==. & date
f. st.2==. & date f. st.3==.)
As you can see I computed the survivaltime not depending on the status
(because I did not know how to work around the change from 0 to a status
of 1-3) but I assumed that if I have Status 1 there has to be a date in
"date for status 1".
And here is my problem, because, as you can see at ID 3, sometimes I have
a status (in this case 3) but I do not have date information in "date f.
st.3". Because of this my survivaltime is computed wrong.
Because I know the year when the person "died" I would like to randomly
generate a "death date" between 01.01. and 31.12. in the death year for
the correct colum? (So that if the person dies because auf reason 3 I get
a date in colum "date f st.3" and not only for the year of death (in case
of ID3 2002) but also the same date in 200 and 2001, as seen in the
excerpt.
Could somebody help my how to do this?
Also I would like to know how to change the pending state in the years
before the death. So that I do not have
ID Year survivaltime status but have ID Year
survivaltime status
1 2000 1098 0 1 2000
1098 1
1 2001 1098 0 1 2001
1098 1
1 2002 1098 0 1 2002
1098 1
1 2003 1098 1 1 2003
1098 1
Thank you so much for your help in advance
Frauke
___________________________________
Frauke Rüther, Dipl.-Kffr., M.A.
Research Associate
University of St.Gallen
Institute of Technology Management
Dufourstrasse 40a
CH - 9000 St. Gallen
Phone +41 (0)71 224 7225
Fax +41 (0)71 224 7301
Email frauke.ruether@unisg.ch
Web www.item.unisg.ch
*
* 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/