Statalist


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

RE: RE: st: random date generator


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
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

thank you for your quick reply and your advices. I tried it but still
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 
decison was made.

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/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index