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]

Re: st: how to construct a mean squared Euclidean measure?


From   David Kantor <[email protected]>
To   [email protected]
Subject   Re: st: how to construct a mean squared Euclidean measure?
Date   Thu, 17 Feb 2011 12:56:13 -0500

Hi.

I don't follow all of what's happening here, but what you want looks like a Mahalanobis distance measure.
Check
 ssc desc mahapick

If that fits, you would use -mahascores-, possibly with the -euclidean- option (or maybe not).

HTH
--David

At 12:15 PM 2/17/2011, Mike Lacy replied to Chanchal:

>
>Date: Wed, 16 Feb 2011 16:24:57 +0000
>From: "[email protected]" <[email protected]>
>Subject:
>
>Hi all,
>
>I am using Stata 10.1. I want to create a variable which captures the
>dissimilarity measure of a member who exit from a work group, sorted by firm
>and year. The dissimilarity is calculated in terms of the member¡¯s job
>tenure in the group with respect to other members¡¯ job tenures. More
>precisely the measure I am trying to construct is the mean squared Euclidean
>distance of a focal member i  from each incumbent team member j  and is
>given as: ¡Ì( ¡Æ(Xi ¨C Xj)2/(n-1)), where Xi is the tenure of the focal
>individual i, Xj is the tenure of incumbent j, with i not equal to j and n
>is the number of group members. Does anyone have an idea how to construct
>this measure using Stata? For more clarity, let me describe the data
>structure as below.
>
>
>
If I understand Chanchal correctly, I think this will work.  It is
probably not the most efficient approach, as it involves looping over cases,
but it ran in a few seconds on my puny machine even when I expanded
the data by 1000. A little byable program would probably be faster.

clear
input ObservationID Year FirmID MemberID Tenure
 1 1960 1 1 4
 2 1960 1 2 2
 3 1960 1 3 1
 4 1960 2 4 2
 5 1960 2 5 1
 6 1961 1 1 4
 7 1961 1 3 2
 8 1961 2 2 0
 9 1961 2 4 3
 10 1961 2 5 2
end
//
egen group = group(FirmID Year)  // I think this is what is intended
sort group
egen case1 = min(_n), by(group)
egen caseN = max(_n), by(group)
gen dij2 = 0
forval i = 1/`=_N' {
   quiet replace dij2 = dij2 + (Tenure- Tenure[`i'] )^2 ///
         if inrange(`i', case1, caseN)  // restrict to group members
}
// Inspect results before dividing, easier to check by eyeball
by group: list FirmID Year Tenure dij2
//
quiet replace dij2 = dij2/(caseN - case1) // n-1 within group

Regards,
=-=-=-=-=-=-=-=-=-=-=-=-=
Mike Lacy, Assoc. Prof.
Soc. Dept., Colo. State. Univ.
Fort Collins CO 80523 USA
(970)-491-6721


*
*   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