Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

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

From   "Anjali Mahendra" <[email protected]>
To   <[email protected]>
Subject   st: Allocating values from a matrix to a new variable in Stata
Date   Tue, 3 May 2005 13:41:04 -0400


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

Whenever a record has X=Y, I want to introduce a new variable distance =
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 Mahendra
Doctoral student
Department of Urban Studies and Planning
Massachusetts Institute of Technology

*   For searches and help try:

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