Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Average when -inrange()-

From   Joseph Monte <>
To   statalist <>
Subject   st: Average when -inrange()-
Date   Thu, 17 Nov 2011 22:06:27 +0000

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.


*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index