Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Average when -inrange()-
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: Average when -inrange()-
Date
Thu, 17 Nov 2011 23:33:25 +0000
Just use the same -if- condition together with -summarize-. Same idea
of initialising a variable before the loop and -replace- within the
loop.
Nick
On Thu, Nov 17, 2011 at 10:06 PM, Joseph Monte <[email protected]> wrote:
> Dear Statalisters,
>
> The code below gives me the number of observations (i.e. count1) when
> "date2" occurs between two dates - "ninetydaysbefore" and "date1" -
> based on "group". I also need the average of another variable called
> "price" of the observations that are counted. I am not sure how to
> incorporate it within the loop below.
>
> sort group date2
> gen count1=.
> qui forval i = 1/`=_N'{
> count if group==group[`i'] & inrange(date2,ninetydaysbefore[`i'],date1[`i'])
> replace count1 = r(N) in `i'
> }
>
> I am using Stata 12.
>
> Thanks,
>
> Joe
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
>
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/