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]

From |
Eric Booth <ebooth@ppri.tamu.edu> |

To |
"<statalist@hsphsun2.harvard.edu>" <statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: Data management: lowest value for which some condition is met |

Date |
Sun, 31 Oct 2010 02:49:59 +0000 |

<> *****************! clear inp group round x z Q 1 1 10 1 20 1 1 20 0 20 1 1 30 0 20 1 1 40 0 20 1 2 10 1 40 1 2 20 1 40 1 2 30 1 40 1 2 40 0 40 1 3 10 1 30 1 3 20 1 30 1 3 30 0 30 1 3 40 0 30 2 1 10 0 10 2 1 20 0 10 2 1 30 0 10 2 1 40 0 10 2 2 10 1 30 2 2 20 1 30 2 2 30 0 30 2 2 40 0 30 2 3 10 1 40 2 3 20 1 40 2 3 30 1 40 2 3 40 0 40 end bys group round: egen q2 = min(x) if z==0 bys group round: egen q = min(q2) li Q q *****************! - Eric __ Eric A. Booth Public Policy Research Institute Texas A&M University ebooth@ppri.tamu.edu Office: +979.845.6754 Fax: +979.845.0249 http://ppri.tamu.edu On Oct 30, 2010, at 9:35 PM, Guy Grossman wrote: > Dear list members, > > I would appreciate your help in what seems like a non complicated > task, but unfortunately I am failing to find a simple solution. I have > a dataset such as the following: each group (1:G) plays a game for > several rounds (1:R), and each round has values of the variable x (10, > 20, 30, 40). Z is an indicator variable that can be 0 or 1. My goal > is to create a new variable Q, that measures for each group and round > the lowest value of x for which z==0. for example for group 1 in > round 1 20 is the lowest x for which z=0, so Q is assigned the value > 20 for all group==1 and round==1. In group 1 round 3, the lowest value > of x for which z=0 is 30, etc. > > I am hoping to get suggestions for a Stata code that can generate Q > efficiently, for a large dataset. > Many thanks! > Guy > > group round x z Q > 1 1 10 1 20 > 1 1 20 0 20 > 1 1 30 0 20 > 1 1 40 0 20 > 1 2 10 1 40 > 1 2 20 1 40 > 1 2 30 1 40 > 1 2 40 0 40 > 1 3 10 1 30 > 1 3 20 1 30 > 1 3 30 0 30 > 1 3 40 0 30 > 2 1 10 0 10 > 2 1 20 0 10 > 2 1 30 0 10 > 2 1 40 0 10 > 2 2 10 1 30 > 2 2 20 1 30 > 2 2 30 0 30 > 2 2 40 0 30 > 2 3 10 1 40 > 2 3 20 1 40 > 2 3 30 1 40 > 2 3 40 0 40 > * > * 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/ * * 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: Data management: lowest value for which some condition is met***From:*Guy Grossman <guygrossman1@gmail.com>

**References**:**st: Data management: lowest value for which some condition is met***From:*Guy Grossman <guygrossman1@gmail.com>

- Prev by Date:
**st: Data management: lowest value for which some condition is met** - Next by Date:
**Re: st: Data management: lowest value for which some condition is met** - Previous by thread:
**st: Data management: lowest value for which some condition is met** - Next by thread:
**Re: st: Data management: lowest value for which some condition is met** - Index(es):