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]

st: Summarizing properties of other group members meeting specified conditions


From   Erik Aadland <[email protected]>
To   <[email protected]>
Subject   st: Summarizing properties of other group members meeting specified conditions
Date   Mon, 27 Jun 2011 14:26:56 +0000

Dear statalist.

After having read the following FAQ http://www.stata.com/support/faqs/data/members.html and experimented with solutions, I am still struggling.

For each project_id, I am trying to generate a variable that for each org_id that meets a specified condition generates the highest observed value on a given variable for another org_id that meets a different specified condition. I think an example is in order:

Example structure:

project_id    org_id    cond_1    cond_2    cond_3    var_1    var_2
1             1         0         1         0         3        0
1             2         1         0         0         0        3
1             3         0         0         1         0        1
2             4         0         1         0         2        0
2             4         1         0         0         0        4
2             5         1         0         0         0        3
2             6         0         1         0         1        0
3             8         0         1         0         1        0

 
For instance, for each project_id I try generate a variable that for each org_id meeting cond_2 == 1 produces the highest value of var_2 for org_id that meets cond_1 == 1. In the case of project_id 1 above org_id 1 should get a score of 3, while org_id 2 and 3 should get a missing value. Some project_ids may have only one observation (consist of a single org_id) as in project_id 3 above, or may not have other org_ids represented that meet the specified condition. Then, it is of course not possible to generate a value on the variable.
 
I have tried with the following code, but I cannot figure out how to specify cond_2 == 1, and it comes out all wrong (Stata does not even accept my code):
 
sort project_id org_id 
gen maxwins = . 
quietly forvalues i = 1/`r(max)' { 
gen include 1 = if org_id != `i' if cond_1 == 1 
egen x = max(var_2 * include), by(project_id) 
replace maxwins = x if org_id == `i' 
drop include x 
} 
 
Is it possible to do this without loops also?
 
Any and all help is very much appreciated.
 
Kind regards,
 
Erik Aadland. 		 	   		  
*
*   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