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

st: RE: help to find maximum drop in a variable


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: help to find maximum drop in a variable
Date   Tue, 2 Mar 2004 14:34:57 -0000

Yuk. 

I tried to solve this from zeroth principles, but 
after a lot of messing around I reached for something 
invented earlier. 

There's probably a cleaner way, but this seems to work. 

egen panel = group(year month day) 
tsset panel hour
tsspell , cond(F.press < press) 
replace _spell = L._spell if L._end  
egen max = max(pressure) if _spell, by(panel _spell) 
egen min = min(pressure) if _spell, by(panel _spell) 
egen range = max(max - min), by(panel) 

where you need to install -tsspell- from SSC. 

Nick 
n.j.cox@durham.ac.uk 

chris wallace
> 
> My colleague has passed to me a query to which I can't find a
> straightforward answer.  I am hoping some of the experts in this group
> could help?
> 
> She has hourly barometric pressure data for many days.  So the dataset
> contains the variables
> 
> year month day hour pressure
> 
> (with 24 hourly observations per day).  During any day the 
> pressure may
> rise and fall.  She wishes to generate a new variable containing the
> maximum fall (constant within year-month-day groups).  That is, for a
> fictitious series of pressure readings
> 
> 90 100 90 80 70 80 65 70 90 80 70
> 
> the maximum fall is 100-70=30.  This is not simply the 
> maximum - minimum
> (100-65), since the pressure rises for one interval in that period
> (70->80).
> 
> She also makes the points:
> - there may be more than one drop per day... i want the largest one
> - if pressure has not dropped at all through out the day, the value
> returned should be zero or negative

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index