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

From |
"Martin Weiss" <martin.weiss1@gmx.de> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: specifying range in forvalues |

Date |
Fri, 21 Nov 2008 17:21:52 +0100 |

Line for the server... " The problem is (I think) that you cannot reference another variable in specifying the range in the forvalues statement. Is that correct?" In your code, you have chosen a possible approach yourself: Do whatever depends on another variable by calculating a -local- and specify the range for -forv- with the dereferenced -local-. Your code should thus read like ******* local X=mod(tn) forvalues i=1/`X'{ .... ******* HTH Martin -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Jason Osterstock Sent: Friday, November 21, 2008 5:17 PM To: statalist@hsphsun2.harvard.edu 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 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/ * * 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/

**References**:**Re: st: IVTOBIT6 Postestimation***From:*Richard Williams <Richard.A.Williams.5@ND.edu>

**RE: st: IVTOBIT6 Postestimation***From:*Filipa Aragão <filipa.aragao@exigoconsultores.com>

**st: specifying range in forvalues***From:*"Jason Osterstock" <JBOsterstock@ag.tamu.edu>

- Prev by Date:
**st: specifying range in forvalues** - Next by Date:
**Re: st: Loop over variables with svyset** - Previous by thread:
**st: specifying range in forvalues** - Next by thread:
**st: RE: specifying range in forvalues** - Index(es):

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