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: Calculate individual distance from other group members


From   Kartika Sari <[email protected]>
To   [email protected]
Subject   Re: st: Calculate individual distance from other group members
Date   Mon, 1 Mar 2010 13:31:17 +0100

Dear Austin,

Thanks a lot for your help.
The problem is solved.
I used the joinby command to first create the pair. and then merge with the
distance.

Best regards,
Kartika

2010/2/24 Austin Nichols <[email protected]>

> Kartika Sari <[email protected]>:
> Like so, then?
>
> clear all
> input gid id ward d1 d2 d3 d4 d5
> 1 1 3 10 4 0 9 7
> 1 2 1 0 6 10 8 5
> 1 3 2 6 0 4 11 3
> 1 4 1 0 6 10 8 5
> 1 5 2 6 0 4 11 3
> 2 1 3 10 4 0 9 7
> 2 2 1 0 6 10 8 5
> 2 3 2 6 0 4 11 3
> end
> qui forv i=1/7 {
> g i`i'=.
> }
> bys gid (id): assert id[1]==1
> bys gid (id): assert id==id[_n-1]+1 if _n>1
> qui forv i=1/7 {
> bys gid (id): replace i`i'=d`=ward[`i']' if ward[`i']<.
> }
> l, noo
>
> See also
> http://www.stata.com/support/faqs/data/members.html
> (though it has some weird editing-induced typos e.g. "We have seen
> that for some problems there is an advantage in using integer
> identifiers which run from 1 and above within each group. If such
> identifiers do not exist, they can be created, as seen in section 5.")
>
> On Tue, Feb 23, 2010 at 4:28 PM, Kartika Sari <[email protected]>
> wrote:
> > Yes, the assert stop the calculation.
> > I tried not to use assert to see what will happen, and try several
> > combination, but off course, it didn't work.
> >
> > so the variables I have:
> >
> > for each individual: GroupID MemberID (1 to 7) WardID (1 to 74) Ward_1
> > Ward_2 etc Ward_74 that shows distance from ward where the person live to
> > other 73 wards (0 for the ward he live in).
> >
> > But, sometimes member of group are only 2 or 3.
> >
> > Any suggestions?
> >
> > thanks in advanced
> > Kartika
> >
> > 2010/2/23 Martin Weiss <[email protected]>
> >
> >>
> >> <>
> >>
> >> " and for the Group, it is not uniform at 5, it is from 1 to
> >> 7."
> >>
> >>
> >> Are the ids within the wards contiguous, i.e. 1,2,3,4? If not, the
> -assert-
> >> line in Austin`s code will stop Stata.
> >>
> >>
> >>
> >>
> >>
> >> HTH
> >> Martin
> >>
> >>
> >> -----Original Message-----
> >> From: [email protected]
> >> [mailto:[email protected]] On Behalf Of Kartika Sari
> >> Sent: Dienstag, 23. Februar 2010 21:46
> >> To: [email protected]
> >> Subject: Re: st: Calculate individual distance from other group members
> >>
> >> Austin,
> >> Thanks for your reply. Yes, i would like to have something like that.
> >>
> >> But, its turn out the actual data is more complicated than the
> hypothetical
> >> I made before.
> >> I have 74 wards. and for the Group, it is not uniform at 5, it is from 1
> to
> >> 7.
> >>
> >> So?
> >>
> >> Best regards,
> >> Kartika
> >>
> >>
> >> 2010/2/23 Austin Nichols <[email protected]>
> >>
> >> > Kartika Sari <[email protected]>:
> >> > Like so?
> >> >
> >> > clear all
> >> > input gid id ward d1 d2 d3 d4 d5
> >> > 1 1 3 10 4 0 9 7
> >> > 1 2 1 0 6 10 8 5
> >> > 1 3 2 6 0 4 11 3
> >> > 1 4 1 0 6 10 8 5
> >> > 1 5 2 6 0 4 11 3
> >> > end
> >> > forv i=1/5 {
> >> > bys gid (id): assert id[`i']==`i'
> >> > bys gid (id): g i`i'=d`=ward[`i']'
> >> > }
> >> > l, noo
> >> >
> >> > On Tue, Feb 23, 2010 at 11:22 AM, Kartika Sari <[email protected]>
> >> > wrote:
> >> > > Dear All,
> >> > >
> >> > > In my data, I have  a distance matrix of  wards for each individual.
> I
> >> > also
> >> > > know in which ward they live. The problem is i want to calculate
> ward
> >> > > distance from each individual to each of other members in a group.
> Say
> >> > there
> >> > > are 5 people in a group, so I need to calculate distance for 4
> others
> >> for
> >> > > each person. I am wondering whether there is any syntax for this.
> >> > >
> >> > > The structure of data is something like this:
> >> > >
> >> > > group_id individual_id ward dtoward1 dtoward2 dtoward3 dtoward4
> >> dtoward5
> >> > > distance1? distance2? distance3? distance4?
> >> > > 1 1 3 10 4 0 9 7
> >> > > 1 2 1 0 6 10 8 5
> >> > > 1 3 2 6 0 4 11 3
> >> > > 1 4 1 0 6 10 8 5
> >> > > 1 5 2 6 0 4 11 3
> >> > >
> >> > > Thank you very much in advanced.
> >> > >
> >> > > Best regards,
> >> > > Kartika
> >> > >
>
> *
> *   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/
>

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