Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: Average and count from a given number of previous observations


From   "Steven Proud" <[email protected]>
To   <[email protected]>
Subject   st: Re: Average and count from a given number of previous observations
Date   Tue, 11 Dec 2007 13:26:29 -0000

One way of doing this would be with a loop

so, could:
tsset date
local i=1
while `i'<=84 {
gen l`i'rainfall=l`i'.rainfall
local i=`i'+1
}
gen lag28rainfall=rsum(l1rainfall-l28rainfall)
gen lag84rainfall=rsum(l1rainfall-l84rainfall)
drop l1rainfall-l84rainfall


gen rain=0
replace rain=1 if rainfall>0
local i=1
while `i'<=84 {
gen l`i'rain=l`i'.rain
local i=`i'+1
}

gen lag28rain=rsum(l1rain-l28rain)
gen lag84rain=rsum(l1rain-l84rain)
drop l1rain-l84rain

I think that should work

**********************************************
----- Original Message ----- From: "Patrick Woodburn" <[email protected]>
To: <[email protected]>
Sent: Tuesday, December 11, 2007 8:01 AM
Subject: st: Average and count from a given number of previous observations



Dear Statalist,

I have weather data for a site in Uganda which I'm hope to compare to
malaria data. My rainfall data is a single variable, sorted by date,
with no missing data, along the following lines:

date rainfall (ml)
01jan2003 12.7 02jan2003 3.0

...

31jun2007 1.3

I would like to make four new variables for each date. Two to represent
the total rainfall across the previous 28 days and across the previous
84 days, and two to represent the total number of days on which
rainfall>0 out of the previous 28 or 84 days. Could someone suggest
how best to do this?

Best regards,

Patrick



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

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