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

Re: st: egen mean function


From   austin nichols <[email protected]>
To   James Avery <[email protected]>
Subject   Re: st: egen mean function
Date   Thu, 18 Aug 2005 18:29:47 -0400

Hmm.  I missed this reply earlier.  The /* 
*/ notation implies one line broken in two.
If you put the code in a do file, it runs fine, I think.

You don't have scnv because
. g byte s=0
should be 
. g byte scnv=0

by analogy to the next loop.  Sorry about that.

On 8/17/05, James Avery <[email protected]> wrote:
> Austin,
> 
> Thanks. But I don't have a scnv variable, just mean
> cnv and nd. I tried what you suggested and i get
> "invalid syntax" after
> 
> forval d=1/7 {
>    replace scnv=max(0,scnv)+ /*
>  */
> max(0,mcnv[_n-`d']*inrange(nd[_n-`d'],nd-7,nd-1)) if
> nfirst==0
>   }
> 
> Or I don't know what scnv is suppose to be?
> 
> James
> 
> 
> --- austin nichols <[email protected]> wrote:
> 
> > The first egen should read, of course,
> > . egen mcnv=mean(cnv), by(nd)
> >
> > and you will almost certainly want to clean up after
> > the commands below:
> > . egen mean7day=max(m7cnv), by(nd)
> > . drop mcnv scnv cnv m7cnv nfirst
> >
> > On 8/17/05, austin nichols <[email protected]>
> > wrote:
> > > I assume you have numeric date nd, and compute
> > mean cnv across
> > > individuals as, e.g.
> > > . egen mcnv=mean(cnv), by nd
> > >
> > > If you have data on every day, or you don't care
> > if any are missing,
> > > and you really want the prior 7 calendar days, you
> > could start with
> > > . bys nd: gen byte nfirst=(_n!=1)
> > > . sort nfirst nd
> > > . set obs `=_N+7'
> > > . replace nd=0 if nd==.
> > > . g byte s=0
> > > . forval d=1/7 {
> > >    replace scnv=max(0,scnv)+ /*
> > >  */
> > max(0,mcnv[_n-`d']*inrange(nd[_n-`d'],nd-7,nd-1)) if
> > nfirst==0
> > >   }
> > > . g byte ccnv=0
> > > . forval d=1/7 {
> > >   replace ccnv=ccnv+(mcnv[_n-`d']!=. &
> > inrange(nd[_n-`d'],nd-7,nd-1)!=0)
> > >   }
> > > . g m7cnv=scnv/ccnv
> > >
> > >
> > > On 8/17/05, James Avery <[email protected]>
> > wrote:
> > > > Dear all,
> > > >  I would like to create a new variable, prior
> > > > week campaign news volume (PWCNV) that is the
> > mean CNV
> > > > for the prior 7 days. Is it possible to do this
> > with
> > > > the egen mean function or with another egen
> > function?
> > >
> >
> > *
> > *   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/
> >
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://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