Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Adding a "keep" option to the -sample- function

    Hi all,

    I regularly draw samples from populations for conducting surveys and one thing that has always confused me is Stata's lack of a option to keep all the data and simply mark the selected values as 1's (and the unsampled values as 0's). Is there a reason this was left out? If I roll my own modified version of this command, and I going to create some problem that Stata long ago sidestepped by not creating this functionality?

  • #2
    Only the developers at Stata could tell you why they chose this design for -sample-. Suffice it to say, however, that the workaround is very simple. After creating the sample, just -merge- that back to the original sampling frame data set. The sample will then be those observations for which _merge == 3, and the _merge == 1 observations are the rest. (There should be no _merge == 2 observations.)

    Comment


    • #3
      I like the user-written module -gsample- (SSC), which can do what is requested, among many other nice things.
      Code:
      sysuse auto
      gsample 20, wor gen(insample)
      tab insample

      Comment


      • #4
        It's been a while, but this might help too.

        Code:
        . search swor, sj historical
        
        Search of official help files, FAQs, Examples, and Stata Journals
        
        SJ-5-1  dm86_1  . . . . . . . . . . . . . . . . . . . Software update for swor
                (help swor if installed)  . . . . . . . . . . . . . . . . .  N. J. Cox
                Q1/05   SJ 5(1):139
                swor rewritten to use sort, stable for reproducibility and
                sortpreserve for compatibility; help file also modernized
        
        STB-59  dm86  Sampling without replacement: abs. sample sizes & keeping all obs
                (help swor if installed)  . . . . . . . . . . . . . . . . .  N. J. Cox
                1/01    pp.8--9; STB Reprints Vol 10, pp.38--39
                samples without replacement a specified sample size;
                alternative to sample

        Comment

        Working...
        X