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 09:17:16 -0500

...
Woops, my code below doesn't bother to save the dataset...
the following 2 lines should be changed:

if `x'==1910 & `i'==1 save mysample
else append using mysample
should be

if !(`x'==1910 & `i'==1) append using mysample
save mysample, replace

Michael Blasnik

----- Original Message ----- From: "Michael Blasnik" <[email protected]>
To: <[email protected]>
Sent: Tuesday, October 31, 2006 7:15 AM
Subject: Re: st: Sample command question

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