[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Alexandru Voicu" <voicu@iza.org> |

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

Subject |
st: RE: programming help |

Date |
Tue, 22 Feb 2005 14:35:00 +0100 |

I am no specialist in STATA. There are at least a couple of ways you can do this. I tried two which work very well in gauss from which I am borrowing conventions. If you are more confortable working with vectors 1. Sort X from the smallest to the largest and Y from the largest to the smallest. 2. construct one indicator vector ind which takes value 1 if x .ge y, 0 else, where .ge is element by element x greater or equal to y 3. result = x .* ind + y .* (1-ind), where .* is element by element multiplication If you want to construct a loop 1. Sort X from the smallest to the largest and Y from the largest to the smallest. 2. Construct the result vector equal to the sorted x. 3. initialize the cycle by letting i=1, and test = difference btw the first elements of sorted y and x i.e. test = y[1,1]-x[1,1]; 4. do while test > 0 5. inside the loop Result[I,1] = y[I,1]; i=i+1; Test = y[I,1]-x[I,1]; 6. Close the loop. -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of MITRA PINAKI (MAR1PXM) Sent: Tuesday, February 22, 2005 1:58 PM To: statalist@hsphsun2.harvard.edu Subject: st: programming help Dear all, I am struggling with the following problem and wondering if I can get any help on this. I have two row vectors, X=(x11, x21, x31, ..., xn1)' and Y=(y11, y21, y31, ..., yn1)' where n=300 (I have 300 elements in each of the row vectors). My problem is the following: 1) I need to calculate the largest value of Y and the smallest value of X. 2) If the largest value of Y is grater than the smallest value of X, replace the smallest value of X by the largest value of Y. 3) At the next step, ignore the previous largest value of Y and find the largest from the rest of the 299 elements of Y. Also for X, find the smallest value of X from the rest of the 299 elements of X and if the largest value of Y is grater than the smallest value of X, replace the smallest value of X by the largest value of Y. 4) The loop stops when the largest value of Y from the rest of Y elements is less than equal to the smallest value of X from the rest of X elements. 5) Construct the new X vector (X_NEW) with the new elements of Y after replacement keeping the unchanged elements of X. My problem is that I am not able to construct the loop correctly and getting no where. Thank you for your help. Pinaki _____________________________ Pinaki Mitra UPS Capital 35 Glenlake Parkway, NE Atlanta, GA 30345 Office: (404) 828-6759; 5-490-6759 (UPS Atlas) Fax: (404) 828-6660 Cell: (404) 668-6575 Web: www.upscapital.com * * 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/

**References**:**st: programming help***From:*"MITRA PINAKI (MAR1PXM)" <mar1pxm@ups.com>

- Prev by Date:
**Re: st: histogram** - Next by Date:
**RE: st: histogram** - Previous by thread:
**st: programming help** - Next by thread:
**Re: st: programming help** - Index(es):

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