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

st: RE: Averaging within a variable


From   austin nichols <[email protected]>
To   [email protected]
Subject   st: RE: Averaging within a variable
Date   Tue, 12 Jul 2005 21:58:40 -0400

g  Var2=(Var1+Var1[_n-1])/2 if mod(_n,2)==0

-----Original Message-----
From: kelly johnson [mailto:[email protected]]
Sent: Tuesday, July 12, 2005 9:51 PM
Hi,
Quick question: suppose I have a variable like this:
N  Var1
1  12
2  45
3  65
100  15
How can I create a new variable whose first observation is the average of 
Var1[1] and Var1[2], second observation is the avaerage of Var1[3] and 
Var1[4], etc. There will be a total of 50 observations for this new 
variable. Thanks in advance!

*
*   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