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

st: RE: using max and sdev functions more flexibly


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: using max and sdev functions more flexibly
Date   Mon, 4 Nov 2002 15:43:18 -0000

Pezzini,S (pgr)
> 
> as my programming skills are very low, I would like to ask 
> if someone could help me get around a problem that I've 
> been trying to solve without success.
> 
> The starting point is a dataset with inflation for years 
> from 1900 to 1995 and some country codes.
> I would like to use the max and sdev function in order to 
> compute the maximum and the standard deviation of inflation 
> over an interval from 1920 (and successive decades) to 
> every year between 1975 and 1995, by country. 
> If I type:
> 
> by ccode: egen maxinf=max(inflation) if year>=1920
> 
> this only allows me to compute max and sdev over 1920 and 
> 1995, i.e. I get a constant over the whole time interval, 
> not staggered by year. I can't get to incorporate the 
> information "compute the standard deviation or the max UP 
> TO EACH YEAR IN THE INTERVAL [1975; 1995]". 
> 
> Maybe my request will be clearer if I tell you that I was 
> able to get what I wanted with another function, sum. 
> By typing:
> by ccode: gen cuminf=sum(abs(inflation)) if year>=1920
> I was able to compute the cumulative inflation from 1920 up 
> to each year in the interval [1975; 1995]. This was 
> possible because "gen y=sum(x)", computes a sum where the 
> j-th obs on y contains the sum of the first through j-th 
> observations on x. 
> 
> Finally, I am using Stata 7.0 SE in Windows environment.
> 
> Maybe this is a straightforward problem for you, so I would 
> be very grateful if you could point me to a solution.
> 

In addition to Nick Winter's comments, note
that -egenmore- on SSC includes a -record()- 
function for -egen-. 

Nick 
[email protected] 
*
*   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