Statalist


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

Re: RE: st: random date generator


From   frauke.ruether@unisg.ch
To   statalist@hsphsun2.harvard.edu
Subject   Re: RE: st: random date generator
Date   Fri, 4 Sep 2009 14:32:32 +0200

Jeph,

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)?

Thank you for your help!

Best 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/



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