# RE: RE: st: random date generator

 From "Nick Cox" To Subject RE: RE: st: random date generator Date Fri, 4 Sep 2009 14:10:44 +0100

```Just keep one random date within each panel then. As they are random, it
does not matter which one, but choosing the first or the last is
systematic and general.

Thus

bys ID : replace rndday = rndday[1]

picks the first in each panel arbitrarily.

If you want to do this reproducibly, -set seed- beforehand.

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

frauke.ruether@unisg.ch

have
a problem maybe you or other statalist-pros could help me.

You suggested
gen daysinyear=doy(mdy(12,31,year))
gen rndday=int(daysinyear*runiform())
gen rnddate=mdy(1,1,year)+rndday

My problem is that I need one random date per ID for the year in which
the

Based on your suggestions I trie to solve in this way:

Because I need the date in the decison year I used:
bys ID: egen maxyear = max(year)

then I computed the days for the "decison year":
gen daysinyear = doy (mdy (12, 31, maxyear)

But then I failed again. When I use
gen rndday= int (daysinyear*runiform())
I get several random numbers for one ID. But I need only one random
number
per ID, because I need only one "day of decison" for each subject.

Could anybody help me to get compute one random number per ID (in a
panel
data set)?

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