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: Creating variable recording for each individual charateristics of members of OTHER groups


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 10:55:10 +0000

<>

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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index