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 <njcoxstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Summarizing properties of other group members meeting specified conditions |

Date |
Mon, 27 Jun 2011 15:36:36 +0100 |

gen include 1 = if org_id != `i' if cond_1 == 1 would go better as gen include = 1 if org_id != `i' if cond_1 == 1 Nick On Mon, Jun 27, 2011 at 3:26 PM, Erik Aadland <erikaadland@hotmail.com> wrote: > 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? * * 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/

**Follow-Ups**:**RE: st: Summarizing properties of other group members meeting specified conditions***From:*Erik Aadland <erikaadland@hotmail.com>

**References**:**st: Summarizing properties of other group members meeting specified conditions***From:*Erik Aadland <erikaadland@hotmail.com>

- Prev by Date:
**st: clogit:determining number of observations for each level of a categorical variable** - Next by Date:
**Re: st: Getting all independent vars from a set of reg equations** - Previous by thread:
**st: Summarizing properties of other group members meeting specified conditions** - Next by thread:
**RE: st: Summarizing properties of other group members meeting specified conditions** - Index(es):