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

RE: st: systematic sampling


From   "Clint Thompson" <[email protected]>
To   <[email protected]>
Subject   RE: st: systematic sampling
Date   Thu, 09 Sep 2004 11:46:38 -0600

Many Thanks to Nick & Eric...
--clint

>>> [email protected] 9/9/2004 11:33:34 AM >>>
A slightly more general approach can be based 
on variables generated with -egen, seq()- and/or 
-egen, fill()-. 

Nick 
[email protected] 

Eric G. Wruck
 
> Clint Thompson wrote:
> 
> >I want to sort then keep every 5th observation, of a 
> fictitious dataset.  Aside from going into the data editor 
> and manually deleting observations one-by-one (or using a 
> series of drop/keep commands), is there a more elegant way to 
> do this??  My initial  idea was to generate a new variable using the
> >_n  system variable then keeping only those observations 
> divisible by, say, five.  Example:
> >
> >sort varname
> >gen obsno = _n
> >keep if (obsno/5)
>  
> 
> Here's a quick example using the mod() function available in Stata:
> 
> . l
> 
>      +----+
>      |  y |
>      |----|
>   1. | 20 |
>   2. | 24 |
>   3. | 28 |
>   4. | 32 |
>   5. | 46 |
>      |----|
>   6. | 36 |
>   7. | 40 |
>   8. | 44 |
>   9. | 48 |
>  10. | 52 |
>      +----+
> 
> . keep if mod(_n,5) == 0
> (8 observations deleted)
> 
> . l
> 
>      +----+
>      |  y |
>      |----|
>   1. | 46 |
>   2. | 52 |
>      +----+

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



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