Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: RE: matrix dissimilarity


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: matrix dissimilarity
Date   Fri, 7 Jan 2011 13:28:31 +0000

Look again at the help for -foreach- to see that what you want is more likely to be 

     matrix dissimilarity DE`p'`sec' = att1 att2 att3 att4

However, your syntax does rather depend on the levels of -p- and -sec- being zero or positive integers, which I can't check from here, so that the resultant matrix names are legal. Moral: Pose examples using datasets everyone can try. 

Also, if p = 11 and sec = 2 you are naming the resultant matrix DE112, which is also going to be what you will try if p = 1 and sec = 12. Moral: use an underscore to disambiguate: 

     matrix dissimilarity DE`p'_`sec' = att1 att2 att3 att4

But even that does work, the dissimilarity matrices will be all the same without extra restrictions on the right-hand side! 

Nick 
[email protected] 

Alp Eren Yurtseven

I want to create a matrix for each sector and year, holding the 
Euclidean distance between all the observations for variables att1 att2 
att3 att4. p and sec denote year and sector respectively. I want to do 
this with a nested loop:

levelsof p,local(y)
levelsof sec,local(s)

foreach p in `y' {
     foreach sec in `s' {
     matrix dissimilarity DE`s'`y'=att1 att2 att3 att4
     }
}

I am not very familiar with loop structures in Stata and not 
surprisingly I get an invalid syntax error. I'd be very glad if you 
could give me some hints to solve this problem. Thanks in advance.


*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index