Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: RE: st: geometric mean with foreach


From   Maarten buis <[email protected]>
To   [email protected]
Subject   RE: RE: st: geometric mean with foreach
Date   Tue, 13 Dec 2005 09:24:36 +0000 (GMT)

on Tue 12/13/2005 3:56 AM Abdelrahmen wrote:
> with your solution it is difficult to create variable year
> the new form of my data is:
>                         price1          price2
> period:801              100             100
> period:802              100.3           100.7
> .
> .
> .
> period:032              127                     130
> given this structure what is the bes way to create a gometric
> mean for periods 801 to 8012; 802 to 811 and so on

if your data is sorted that way, than it is quite easy to make a 
year variable. The system variable _n contains the number of the 
current observation. We can use that by manipulating it so that 
it does not increment every observation but only every 12th 
observation, for example: -gen year = 1979 +ceil(_n/12)- . 
(note that -sort- would screw the order up, it has no way to know  
that 032 is later than 801) Now you can make the variables you 
want by -egen geomprice1 = gmean(price1), by(year)- , -egen geomprice2 = gmean(price2), by(year)-,
... , -egen geompricen = 
gmean(pricen), by(year)-

HTH,
Maarten

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

visiting adress:
Buitenveldertselaan 3 (Metropolitan), room Z214

+31 20 5986715

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




	
	
		
___________________________________________________________ 
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.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