Friday, February 17, 2006

Re: st: random pick from a custom distribution

Daniel wrote:

I have generated an empiric frequency distribution, using -contract-, such that I have two variables-- the variable of interest (hour of the day that a patient is discharged from the hospital), and the cumulative frequency of from a set of empiric observations.

How can I generate a function which picks random hours in a frequency proportional to this distribution? ---------------------------------------------

I'm sure it can be done at a contracted dataset, but it is easier if you expand it first:

// I generate an artificial dataset clear set obs 24 generate hour=_n-1 generate _freq=round(100*uniform())

// Expand the dataset expand _freq drop _freq

// Identify a 10% random sample generate include=uniform()<0.1 keep if include==1 contract hour

You might also use the -sample- command.

Hope this helps Svend

__________________________________________

Svend Juul Institut for Folkesundhed, Afdeling for Epidemiologi (Institute of Public Health, Department of Epidemiology) Vennelyst Boulevard 6 DK-8000 Aarhus C, Denmark Phone: +45 8942 6090 Home: +45 8693 7796 Email: sj@soci.au.dk __________________________________________

* * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/


Tag:


Links to this post:

Create a Link



<< Home

This page is powered by Blogger. Isn't yours?