Statalist


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

st: specifying range in forvalues


From   "Jason Osterstock" <JBOsterstock@ag.tamu.edu>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: specifying range in forvalues
Date   Fri, 21 Nov 2008 10:16:37 -0600

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
JBOsterstock@ag.tamu.edu
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/



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