Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: how to generate a variable representing a maximum value within the same category


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: how to generate a variable representing a maximum value within the same category
Date   Sat, 19 Jan 2008 11:57:46 +0000 (GMT)

--- "FUKUGAWA, N." <[email protected]> wrote:
> I want to generate a new variable (var2) representing a maximum
> value within the same year.

The easiest way is to use -egen-, see the example below:
(I have replaced one the values of var1 with a missing value to show
what happens in that case)

*--------------- begin example ----------------
drop _all
input year	var1
1997	14	
1997	32	
1998	18	
1998	.		
1998	50		
1998	1
1999	3	
1999	23	
1999	37	
end

bys year: egen var2 = max(var1)
list
*------------------- end example -------------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )

Hope this helps,
Maarten

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


      __________________________________________________________
Sent from Yahoo! Mail - a smarter inbox http://uk.mail.yahoo.com

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index