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 00:46:15 -0500

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.

The code I have now works with respect to creating the samples, it just
needs help on how to save the samples in a more concise form.

forval x =1910/2000 {
local i=1
	while `i' <=10 {
		use `x'

		sample 5, count
		save sample`x'`i', replace
		local i= `i' +1
}
}
-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
Sent: Monday, October 30, 2006 3:59 AM
To: statalist@hsphsun2.harvard.edu
Subject: RE: st: Sample command question

Partly to echo Richard's comment. 

One key thing that remains unclear is quite what you mean by 
"database", as Stata has no such notion. Is this a Stata 
dataset or a bundle of Stata datasets, or is the Stata 
processing a means towards an end of holding the data
in some other form? 

Similarly, I don't know what "term" means here either. 

In broad terms, your specification seems a long way from the code 
you posted. 

Perhaps you should work on the specific suggestions already 
made, as I don't think your problem is yet precise enough 
for anyone to write down code without making further wild 
guesses. 

Nick 
n.j.cox@durham.ac.uk 

David McClintick
 
> Perhaps I can clear up what it is that I am trying to accomplish.
> 
> I have 91 variables. I want to generate 10 random samples of each
> variable. So, for instance, for the first variable I would 
> have 10 sets
> of 5 observations, only using observations from that variable. Thus,
> when all is said and done, I should have 10 individual databases, with
> each database containing 91 variables with 5 terms in each one.
> 
Richard Williams
 
> At 09:46 PM 10/29/2006, Nick Cox wrote:
> >Richard's line of code does what you ask.
> >It works on just the variable that you are focusing on.
> >
> >I can see some other problems, some trivial, some
> >not so, that you will face.
> 
> Other than the 20 problems Nick points out, it should work fine.  :)
> 
> One other thing I wondered about - each of the little mini-samples is 
> going to include all the variables.  Is that what you want, or did 
> you just want each sample to include the X in question?  You keep on 
> referring to "5 terms" rather than "5 cases" which is why I ask this.
> 
> Without knowing anything about the Xs, it is hard to tell what the 
> purpose of the program is, but I do wonder if maybe there aren't some 
> other logical errors lurking out there or if there are better ways of 
> approaching it.

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