Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

RE: st: Randomly change a date in Stata


From   Tim Evans <Tim.Evans@wmciu.nhs.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Randomly change a date in Stata
Date   Tue, 19 Jun 2012 12:37:19 +0100

Nick,

Thanks for your reply. 

If I use the following, I don't actually manage to re-create the same date:

set seed 339487731
gen date7 = datediag + ceil(11 * runiform()) - 6
gen date8 = datediag + ceil(11 * runiform()) - 6

The dates are different - do you know why this may be?

Best wishes

Tim


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
Sent: 19 June 2012 11:18
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: Randomly change a date in Stata

A random integer from a discrete uniform on the integers [-5,5] is

ceil(11 * runiform()) - 6

so you just add that, or equivalently subtract it. -set seed- first
for reproducibility.

Nick

On Tue, Jun 19, 2012 at 10:58 AM, Tim Evans <Tim.Evans@wmciu.nhs.uk> wrote:

> I have dates of birth which for the purpose of anonymity in a dataset, I wish to generate a new 'annoynmised date of birth' whereby for a list of dates, I randomly add or subtract up to 5 days and generate the new date. Does anyone have a suggestion as to how I might do this in Stata?
>
> I'm using Stata 11.2 and the dates are in date format (i.e. not strings).

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

_DISCLAIMER:
This email and any attachments hereto contains proprietary information, some or all of which may be confidential or legally privileged. It is for the exclusive use of the intended recipient(s) only. If an addressing or transmission error has misdirected this e-mail and you are not the intended recipient(s), please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail or any attachments, as this may be unlawful.


*
*   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   |   Site index