Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: How to (almost) randomly reduce the number of observations?


From   Maarten buis <maartenbuis@yahoo.co.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: How to (almost) randomly reduce the number of observations?
Date   Tue, 20 Apr 2010 07:02:18 +0000 (GMT)

--- On Mon, 19/4/10, Dimitrije Tišma wrote:
> I would like to ask how to reduce number of observations
> randomly BUT in a way that all observations are kept that
> are related to the person who still in the dataset. 

*---------- begin example -------------
// create some example data
clear
set obs 100
gen id = _n
expand 10
bys id : gen t = _n
sort id t
list in 1/22, sepby(id)

// randomly drop 50%
bys id: gen u = runiform() if _n == 1
bys id: egen uu = total(u)
keep if uu < .5
drop u uu
*----------- end example ----------------

hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://www.maartenbuis.nl
--------------------------


      

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index