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

Re: st: systematic sampling


From   "Eric G. Wruck" <[email protected]>
To   [email protected]
Subject   Re: st: systematic sampling
Date   Thu, 9 Sep 2004 13:28:46 -0400

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 |
     +----+

-- 

===================================================

       Eric G. Wruck
       Econalytics
       2535 Sherwood Road
       Columbus, OH  43209

       ph:      614.231.5034
       cell:    614.327.4182
       fax:     614.231.5039
       eFax:    614.573.6639
       eMail:   [email protected]
       website: http://www.econalytics.com

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