Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Sample command question


From   "David McClintick" <mcclin47@msu.edu>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Sample command question
Date   Tue, 31 Oct 2006 01:46:58 -0500

I apologize, I misread the code. I understand that your suggestion
returns var1 as the unique values of the observations the sample has
selected. However, is it possible to instead have the sample variables
be expressed as their actual values and placed in the first 5
observations?

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of David
McClintick
Sent: Tuesday, October 31, 2006 1:31 AM
To: statalist@hsphsun2.harvard.edu
Subject: RE: st: Sample command question

After looking at that code, I realize that I have not been clear enough.
What I meant by "without replacement" was that I wanted each of the 10
samples of each dataset to be taken from the original dataset, meaning
that while no observation could be repeated within the sample, it could
conceivably be repeated across samples. With your suggestion, it returns
varying numbers of observations, which I believe is caused by the
aforementioned issue. Additionally, it seems to return all of the sample
observations in the first variable?

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Austin
Nichols
Sent: Tuesday, October 31, 2006 12:59 AM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: Sample command question

David McClintick--
You need not use -sample- to extract five observations, and you need
not save each sample constructed without replacement as a separate
dataset.

set seed 123
forval x =1910/2000 {
 use `x', clear
 ds
 keep if !mi(`r(varlist)')
 forval i=1/10 {
  gen s`i'=uniform()
  sort s`i'
  gen sample`i'=(_n<=5)
  drop s`i'
  }
 egen rsum=rowtotal(sample*)
 keep if rsum>0
 save sampled_`x'
}

On 10/31/06, David McClintick <mcclin47@msu.edu> wrote:
> I apologize for not properly explaining what I intend to do. Hopefully
> this time I will clear up the confusion.
>
> I have 91 datasets, named 1910 to 2000 in increments of 1. Each
dataset
> has 1 variable. What I wish to do, is use stata to take a 5
observation
> sample from each dataset, without replacement, and then do so 10 times
> so that I have 10 random samples of 5 observations from each complete
> dataset. Now, I realize that the way I have it set up, Stata would
save
> the results in 910 different new datasets. This is where things become
> more difficult. If possible, I would like the results to be saved in a
> single dataset for each original dataset, storing each random sample
as
> a different variable. So, instead of 910 new datasets, I would have 91
> datasets with 10 variables in each dataset, and each variable
containing
> 5 observations.
*
*   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/

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