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

Re: st: re: averaging within a variable


From   austin nichols <[email protected]>
To   [email protected]
Subject   Re: st: re: averaging within a variable
Date   Tue, 12 Jul 2005 23:29:14 -0400

That should read

foreach v of varlist var1-var100 {
  g  m_`v'=(`v'[_n*2-1]+`v'[(_n+1)*2-2])/2 if _n<=50
  }

of course.

On 7/12/05, austin nichols <[email protected]> wrote:

> If you _really_ want the means coded in the first fifty observations,
> and the last fifty observations to be missing, and you don't have
> Stata 9, or you happen not to want to use Kit's mata code, you could:
> 
> foreach v of varlist var1-var100 {
>  g  m3=(`v'[_n*2-1]+`v'[(_n+1)*2-2])/2 if _n<=50
>  }

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