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: Generating variable that counts number of appearances


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Generating variable that counts number of appearances
Date   Sun, 1 Apr 2012 09:14:22 +0100

This is just to underline that the help for -countmatch- explains how
to do this.


On Sat, Mar 31, 2012 at 9:55 AM, Nick Cox <[email protected]> wrote:
> Use
>
> . ssc desc countmatch
>
> in a loop across friend variables.
>
> Nick
>
> On Sat, Mar 31, 2012 at 6:29 AM, Timothy Malacarne
> <[email protected]> wrote:
>> Hello,
>>
>> I'm attempting to create a variable the counts the number of times a unique id value for existing variable 1 appears across all observations variable two.  In this case, individuals have unique IDs.  They are then asked to name their friends, who appear by their id number in a series of friend variables.  Each value is unique in the "ID" variable, but 3 people might nominate the same ID value under the Friend variable.  I want to count up how often each individual is named a friend by others.
>>
>> To do so, I wrote this code:
>>
>> gen NumberFriends=.;
>>
>> forval k =   90316050/99798989 {;  *the range of ID values
>>                egen tot`k' = total(Friend1ID==`k');
>>                replace NumberFriends=tot`k' if `k'==ID;
>>                drop toad`k';
>>        };
>>
>> Unfortunately, it needs to loop over all values in the ID range for it to work and I don't have the computational power to do this in a reasonable amount of time.  Is there a computationally more efficient way to count up ID cross references in 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