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

From |
Nick Winter <nw53@cornell.edu> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Allocating values from a matrix to a new variable in Stata |

Date |
Tue, 03 May 2005 13:48:55 -0400 |

Assuming you have the distance matrix in a Stata matrix called "D", then this should do it:

. generate distance = D[x,y]

(I am assuming that the diagonal of the distance matrix contains zeros, so there is no need to deal with x==y as a separate step.

If you have missing values for either x and/or y, you might need to modify:

. generate distance = D[x,y] if !missing(x) & !missing(y)

--Nick WInter

At 01:41 PM 5/3/2005 -0400, you wrote:

--------------------------------------------------------Hi, I'm using Intercooled Stata 8, and am not an experienced user. It will be great if someone can help me out with this. I have a dataset where I have about 18,000 records each having a value for X and another for Y that ranges from 1 to 32. I have another 32*32 matrix that gives the distances between all X and Y pairs. Whenever a record has X=Y, I want to introduce a new variable distance = zero. Otherwise, I want to assign distance = the appropriate distance value for (X,Y) from this matrix I have. For example, if X=1 and Y=1, distance = 0. If X=1 and Y=2, distance = 25 (value obtained from the distance matrix) If X=2 and Y=1, distance = 25 (same as above) If X =1 and Y=3, distance = 15 ...... And so on. Can someone please suggest the most efficient way to do this in Stata? Many thanks, Anjali ------------------------------ Anjali Mahendra Doctoral student Department of Urban Studies and Planning Massachusetts Institute of Technology ------------------------------ * * 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/

Nicholas Winter 607.255.8819 t

Assistant Professor 607.255.4530 f

Department of Government nw53@cornell.edu e

308 White Hall falcon.arts.cornell.edu/nw53 w

Cornell University

Ithaca, NY 14853-4601

*

* 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: Allocating values from a matrix to a new variable in Stata***From:*"Anjali Mahendra" <anjalim@MIT.EDU>

- Prev by Date:
**st: Allocating values from a matrix to a new variable in Stata** - Next by Date:
**st: Another Stata 9 Windowing Problem** - Previous by thread:
**st: Allocating values from a matrix to a new variable in Stata** - Index(es):

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