Is there a good method for generating random (but valid) dates in Stata?
Gareth
Gareth
args beg end
local d1 = date("`beg'", "MDY")
local d2 = date("`end'", "MDY")
local n1 = min(`d1', `d2')
local n2 = max(`d1', `d2')
local rdate = `n1' + round(runiform() * (`n2' - `n1'))
noi di %td `rdate'
. run rdate "1/15/2008" "1/15/2010" 29may2009 . run rdate "1/15/2008" "1/15/2010" 03apr2008 . run rdate "1/15/2008" "1/15/2010" 11apr2009
Comment