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]

From |
Nick Cox <[email protected]> |

To |
"[email protected]" <[email protected]> |

Subject |
Re: st: Creating variable recording for each individual charateristics of members of OTHER groups |

Date |
Wed, 15 Jan 2014 16:16:45 +0000 |

Good catch. This makes the FAQ originally cited appear relevant again; the key point is defining the groups. However, the concatenation Team+Opponent may not uniquely define Team and Opponent with string identifiers more than one character long. Think "4 244" and "42 44". Better to insert a space, as I just did. Nick [email protected] On 15 January 2014 16:09, Robert Picard <[email protected]> wrote: > This is much easier to do if you group observation by game played. An > individual's peers are simply the difference between the total number > of players with the same Charateristic in the game minus the total in > player's team with the same Charateristic. > > Robert > > * ----------------- begin example ------------------------------ > clear > input Individual Day str1 Team str1 Opponent str5 Char Score > 1 1 A B Red 2 > 2 1 A B Black 2.5 > 3 1 A B Brown 4 > 4 1 A B Black 1 > 1 1 B A Red 1 > 2 1 B A Black 3 > 3 1 B A Brown 1 > 1 2 A C Red 2 > 2 2 A C Black 2 > 3 2 A C Brown 5 > end > > gen game = cond(Team<Opponent,Team+Opponent,Opponent+Team) > isid Day game Char Team Individual, sort > by Day game Char: gen gametot = _N > by Day game Char Team: gen Teamtot = _N > gen peers= gametot - Teamtot > > list, sepby(Day game Char) noobs > > * ----------------- end example ------------------------------- > > > On Wed, Jan 15, 2014 at 5:55 AM, Nick Cox <[email protected]> wrote: >> <> >> >> This is unlikely to be exactly what you want, but it may give some >> ideas about technique. >> >> clear >> input Individual Day str1 Team str1 Opponent str5 Char Score >> 1 1 A B Red 2 >> 2 1 A B Black 2.5 >> 3 1 A B Brown 4 >> 1 1 B A Red 1 >> 2 1 B A Black 3 >> 3 1 B A Brown 1 >> 1 2 A C Red 2 >> 2 2 A C Black 2 >> 3 2 A C Brown 5 >> end >> >> gen n_others = 0 >> >> qui forval i = 1/`=_N' { >> count if Opponent==Team[`i'] & Day == Day[`i'] & Char == Char[`i'] >> replace n_others = r(N) in `i' >> } >> >> See also >> >> SJ-7-3 pr0033 . . . . . . . . . . . . . . Stata tip 51: Events in intervals >> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox >> Q3/07 SJ 7(3):440--443 (no commands) >> tip for counting or summarizing irregularly spaced >> events in intervals >> >> http://www.stata-journal.com/sjpdf.html?articlenum=pr0033 >> >> Nick >> [email protected] >> >> On 15 January 2014 10:23, Vincenzo Carrieri <[email protected]> wrote: >> >>> I have some problems in generating a variable capturing charateristcs >>> of members of other groups. >>> I read the intersting FAQ >>> http://www.stata.com/support/faqs/data-management/creating-variables-recording-properties/ >>> but I think it does not cover the situation in which the interest is >>> on charateristics of members of other groups. >>> >>> I have a data set like this: >>> >>> Individual Day Team Opponent Team Charateristic Score >>> 1 1 A B >>> Red 2 >>> 2 1 A B >>> Black 2,5 >>> 3 1 A B >>> Brown 4 >>> . >>> . >>> . >>> 1 1 B A >>> Red 1 >>> 2 1 B A >>> Black 3 >>> 3 1 B A >>> Brown 1 >>> . >>> . >>> . >>> 1 2 A C >>> Red 2 >>> 2 2 A C >>> Black 2 >>> 3 2 A C >>> Brown 5 >>> >>> I need to generate a variable recording for each individual and for >>> each day the number of individuals in the opponent team with the same >>> charateristic of individual i playing in team j. >>> I have no problems to generate the same variables recording >>> charateristics of individuals playing in the same team using >>> combination of by, egen and count command: >>> >>> bysort team day charateristics: egen "peer_variable"=count(Score) >>> >>> However, this procedure does not seem to work when the focus is on >>> charateristics of players of the opponent team. If I replace "team" >>> with "opponent team" in the above line command, stata generates me the >>> same identical "peer_variables" built above. I guess this is due to >>> the fact that my procedure is not appropriate when informations are >>> not in the same row. >> * >> * For searches and help try: >> * http://www.stata.com/help.cgi?search >> * http://www.stata.com/support/faqs/resources/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/faqs/resources/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/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:

**References**:**st: Creating variable recording for each individual charateristics of members of OTHER groups***From:*Vincenzo Carrieri <[email protected]>

**Re: st: Creating variable recording for each individual charateristics of members of OTHER groups***From:*Nick Cox <[email protected]>

**Re: st: Creating variable recording for each individual charateristics of members of OTHER groups***From:*Robert Picard <[email protected]>

- Prev by Date:
**st: Recovering files** - Next by Date:
**Re: st: Recovering files** - Previous by thread:
**Re: st: Creating variable recording for each individual charateristics of members of OTHER groups** - Next by thread:
**Re: st: Creating variable recording for each individual charateristics of members of OTHER groups** - Index(es):