Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: specifying range in forvalues


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: RE: specifying range in forvalues
Date   Fri, 21 Nov 2008 18:20:10 +0100

Line for the server...

You can also have Stata evaluate expressions in the range specification...

***********
loc a 1

forv i=`=`a'+1'/`=`a'+4'{
	di `i'
}
***********

HTH
Martin


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Jason Osterstock
Sent: Friday, November 21, 2008 5:17 PM
To: [email protected]
Subject: st: specifying range in forvalues

I am trying to count the number of pairwise values in a distance matrix that
are below a certain threshold. The distance matrices are generated for
consecutive time points and the number of observations at each time point
varies. I have tried to approach this by generating a distance matrix at
each time point using the first loop and would like to summarize the number
below the specified threshold in the second loop. To do that, I think I need
to generate new variables that provide the number of observations at the
time period of interest and then perform the counts in the second loop from
1 to X (where X is the total number of observations at that time point). The
problem is (I think) that you cannot reference another variable in
specifying the range in the forvalues statement. Is that correct? Does
anyone know of an alternative way to specify a range that changes at every
time period? Thanks in advance for the help.

forvalues TimeB=66416(1)66500{
	local TimeB1= `TimeB'+1
	egen byte n = anycount(TimeB), values(`TimeB')
	egen tn=total(n)
	minkowski var2 var3 if TimeB ==`TimeB', datamatrix(dat`TimeB')
distmatrix(dist`TimeB') id(asset)
	matrix list dist`TimeB'
	svmat dist`TimeB'
	local X=mod(tn)
	forvalues i=1(1)X{
		local i1=`i'+1
		count if dist`TimeB'`i' >0 & dist`TimeB'`i' <=10
	}
	drop n
	drop tn
	drop dist*
}

Jason Osterstock, DVM, PhD
Assistant Professor
Texas AgriLife Research
6500 Amarillo Blvd. West
Amarillo, TX 79106
806-677-5600
806-677-5644 Fax
806-335-6363 Cell
[email protected]
http://amarillo.tamu.edu
 



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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