Statalist The Stata Listserver


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

Re: st: Sample command question


From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   Re: st: Sample command question
Date   Tue, 31 Oct 2006 07:15:45 -0500

...
Why not just create one big dataset and then pull it apart at the end:

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

sample 5, count
gen dataset=`x'
gen samplenum=`i'
if `x'==1910 & `i'==1 save mysample
else append using mysample

* delete this line> save sample`x'`i', replace
local i= `i' +1
}
}
* now you have mysample with vars dataset, samplenum, and the variable of interest. You could save pieces however you want using another loop...

Michael Blasnik

----- Original Message ----- From: "David McClintick" <[email protected]>
To: <[email protected]>
Sent: Tuesday, October 31, 2006 12:46 AM
Subject: RE: st: Sample command question



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