Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: RE: generate random sample


From   Steve Samuels <[email protected]>
To   [email protected]
Subject   Re: st: RE: generate random sample
Date   Mon, 16 Jan 2012 00:34:59 -0500

Oops, that last statement should be

"list x fw if fw>0"


Well, that's possible. But Ning is a survey methodologist and he asked about generating "a sample from a population with replacement", so I assumed that he was asking about a survey sample problem. The toy example doesn't appear like a real problem to me.

If I'm wrong, then Phil's method applies. One variant is to expand to single-digit frequencies (multiply the proportions by 10, in this case).  This necessitates a change to Phil's -list- statement.

*************************
clear
* set seed <seednum>
input x prop
1 .2
2 .1
3 .3
4 .3
5 .1
end
gen int fw = 10*prop
expand fw
bsample 3, weight(fw)
list x if fw>0
**************************

Steve
[email protected]


On Jan 15, 2012, at 11:47 PM, David Hoaglin wrote:

Steve,

Isn't it simply a discrete distribution that has the values 1 through
5 with the indicated probabilities?  And the aim is to generate three
random observations from that distribution?

David Hoaglin



On Jan 15, 2012, Steve Samuels wrote:
Ning Li:

Your example is too unrealistic and your question too vague for us to answer.

Is N (population size) really 5? If so, then the "probability distribution" cannot be that of the population.

If population N>5 and there are five "types" of population elements, with the distribution shown, then there is not enough information for Phil's (or anybody's) algorithm to work. Suppose Phil's algorithm draws a selection with x = 3. With the information you have provided, there is no way to link this selection to a specific population element.:

But perhaps you want to draw the sample of n = 3 from N =5 with probability proportional to size, in which case the size measures can be arbitrary. But such size measures will rarely look like the proportions that you show.

So please describe your problem better. .


Steve
[email protected]


On Jan 15, 2012, at 6:54 PM, Philip Ryan wrote:



The following will randomly sample 3 observations on variable x with
replacement from 10,000 observations with the distribution you specified.
Un-comment the -set seed- line (and provide a numeric seed) if you want
reproducibility between runs.  see -help bsample-


clear
* set seed <seednum>
input x fw
1 2000
2 1000
3 3000
4 3000
5 1000
end
expand fw
bsample 3, weight(fw)
list x if fw==1


Phil


Philip Ryan
Professor and Director
Data Management & Analysis Centre [DMAC]
University of Adelaide
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of
[email protected]
Sent: Monday, 16 January 2012 9:22 AM
To: [email protected]
Subject: st: generate random sample

Dear listers

I am using Stata/MP 11 Windows.

What is the good way to generate a sample from a population with
replacement?

Say, how to generate 3 independent random numbers from population
(1,2,3,4,5) with probability distribution (0.2, 0.1, 0.3, 0.3,0.1)?

Many thanks for the help.

Ning

--
Ning Li
Survey Methodologist
Melbourne Institute of Applied Economic and Social Research The
University of Melbourne
Tel:  +61 3 9035 4949   Fax: +61 3 8344 2111
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index