Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Capturing unique actors meeting conditions by focal actor and year (excluding focal actor)


From   Erik Aadland <erikaadland@hotmail.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Capturing unique actors meeting conditions by focal actor and year (excluding focal actor)
Date   Tue, 16 Oct 2012 08:52:40 +0000

Dear Statalist.
I am trying to generate a variable "wanted" that by each focal actor and year captures the total number of unique actors (excluding the focal actor) that meet a specified condition (condition == 0) and that the focal actor has occured together with in one or more projects.
This is my data structure:
year     project_id     actor_id     condition     wanted
2000     1              1            1             2
2000     1              2            0             1
2000     1              3            0             1
2000     1              7            1             2
2000     2              1            1             2
2000     2              2            0             1
2000     2              3            0             1
2000     3              4            1             2
2000     3              5            0             1
2000     3              6            0             1
2000     3              .            .             .
2001     4              1            1             2
2001     4              2            0             1
2001     4              3            0             1
.....and so on
So in year == 2000, actor_id == 1 has occurred with 2 unique actor_id (namely 2 and 3) meeting condition == 0 in projects. Therefore, wanted == 2 for actor_id == 1 in year == 2000. 
My attempted code (which is quite wrong):
sort actor_id year projects ;
by actor_id year: gen nvals = _n == 1 ;
sort  actor_id year project_id ;
egen wanted = total(nvals & condition == 0), by(agency_id year) ;
replace wanted = wanted - (nvals & condition == 0) ;
Any input on this problem would be very much appreciated.
Kind regards,
Erik. 		 	   		  
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index