Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: two loops of forval


From   "Ronnie Babigumira" <[email protected]>
To   <[email protected]>
Subject   st: RE: two loops of forval
Date   Thu, 24 Feb 2005 11:14:12 +0100

Thanks David, I tried your suggestion and it does what I want. I didnt
realise that the second loop could start further down into the outer
loop.  I also realise that my question was not clear in the first place,
my apologies for that.

Thanks also to the others who commented on this as well as the pwcorr
postings.

Ronnie

>>> [email protected] 23.02.2005 17:23:59 >>>
The main observation I would make is that anything you want to do only
once for each value of i (everything down to and possibly including the
first "some more stuff"?) should go before the -forval j-. At the
moment, these commands are being repeated unnecessarily for every
different value of j.

I am not familiar with -spatsam- so I can't comment on the use of
this.

David

-----Original Message-----
From: Ronnie Babigumira [mailto:[email protected]]
Sent: 23 February 2005 11:19
To: [email protected]
Subject: st: two loops of forval


Dear all
Im having a little trouble with forval. I would like to

1. Use a master data set
2. Keep observations that fall within a given range of a variable of
values and save that as a data set
3. Draw a sample from this smaller data set and then do a few more
things
4. Change the range in 2
5. Repeat 3

here is a really short version of what I have written


forval i = 5000(5000)20000 {
	forval j = 5(5)15 {
		u masterdata, clear
		keep if dfor < `i'
		save buffer_`i', replace
		local expl_vbls "bla bla bla"
		//some more stuff

		u buffer_`i', clear
		spatsam, g(`j') x(x) y(y) norest saving(b`i'_space`j')
replace //draw a subsample
		logit def `expl_vbls'

		//some more stuff
	}
}

Im not sure this is doing what I want it to do. Essentially I would
like to implement the first loop

keep if dfor<`i'< 5000

and then on this portion of the data
implement the second loop forval j = 5(5)15

and then go back to the outer loop and increase the value of `i' and
go
over this again.

Kindly advise on how I can proceed with this

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