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

st: RE: two loops of forval

From   "David Harrison" <>
To   <>
Subject   st: RE: two loops of forval
Date   Wed, 23 Feb 2005 16:23:59 -0000

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.


-----Original Message-----
From: Ronnie Babigumira []
Sent: 23 February 2005 11:19
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
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

*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index