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 on April 23, and its replacement, statalist.org is already up and running.


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

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


From   Guy Grossman <guygrossman1@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Data management: lowest value for which some condition is met
Date   Sat, 30 Oct 2010 22:35:57 -0400

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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index