Hello,
I would like to make a sample of the specified size from the elements of a vector. Let's say that you have an abnormal die with six sides unequal. Sides 1 and 6, for example, are twice as wide as the other sides. It's easy to see that when you roll this die repeatedly, the probabilities of landing on each side are 2/8, 1/8, 1/8, 1/8, 1/8, and 2/8, respectively. Suppose that we roll this die a thousand times. How many times will each side appear? R has a simple function sample() that answers this question.
set.seed(10101)
X=sample(1:6, 1000, replace=TRUE, prob=c(2/8, 1/8, 1/8, 1/8. 1/8, 2/8))
table (X)
277 126 113 122 122 240
As expected, 1 and 6 appear about 250 times, respectively, while the others appear about 125 times, respectively.
I haven't found such a single function or command in Stata 15.1. How can I achieve the same or similar result in Stata?
Sang-soo
I would like to make a sample of the specified size from the elements of a vector. Let's say that you have an abnormal die with six sides unequal. Sides 1 and 6, for example, are twice as wide as the other sides. It's easy to see that when you roll this die repeatedly, the probabilities of landing on each side are 2/8, 1/8, 1/8, 1/8, 1/8, and 2/8, respectively. Suppose that we roll this die a thousand times. How many times will each side appear? R has a simple function sample() that answers this question.
set.seed(10101)
X=sample(1:6, 1000, replace=TRUE, prob=c(2/8, 1/8, 1/8, 1/8. 1/8, 2/8))
table (X)
277 126 113 122 122 240
As expected, 1 and 6 appear about 250 times, respectively, while the others appear about 125 times, respectively.
I haven't found such a single function or command in Stata 15.1. How can I achieve the same or similar result in Stata?
Sang-soo
Comment