Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: picking at random

From   baum <>
Subject   st: Re: picking at random
Date   Wed, 12 Jun 2002 08:27:28 -0400

--On Wednesday, June 12, 2002 2:33 -0400 Yanjun wrote:

We have say, by one id, four observations under a variable.  We want
STATA  to randomly pick one observation each time it is asked.  We want
to use the  randomly picked observation for each id in regression.

Any information will be greatly appreciated!  Thanks.
No doubt someone will improve on this, but it works, even if there are unbalanced groups...
Assume your id variable is named 'group':

g rr=uniform()
by group: egen rrm=min(rr)
by group: g select=(rr==rrm)
reg .... if (select)

* For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index