st: RE: How to sample uniformly over a set of specific observations?

 From "Nick Cox" To Subject st: RE: How to sample uniformly over a set of specific observations? Date Sun, 14 Oct 2007 22:51:52 +0100

```Shuffle the data randomly. Then
pick any observation to use. It might as well
be the first.

gen rnd = uniform()
sort rnd
gen var4 = var3[1]

For repeatability, set the seed first.

Nick
n.j.cox@durham.ac.uk

tiago.pereira@incor.usp.br

> Thank you, Svend.
>
> I was not very clear, indeed.
>
> Getting back to my hypothetical dataset:
>
>
> var1 var2 var3
> 0.5 0.5 0.25
> 0.4 0.4 0.16
> 0.3 0.4 0.12
> 0.8 0.4 0.32
> 0.4 0.2 0.08
>
> The objective is to generate a fourth variable, var4, that
> can take any
> value of the variable 3, var3. Hence, the first observation
> of var4 can
> take one out of 5 values of the var3 (0.32, 0.25, 0.16, 0.12,
> 0.08) [with
> equal probabilities] and so on.
>

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