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

From |
"Scott Merryman" <smerryman@kc.rr.com> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: Re: Creating variables = sum(last year) |

Date |
Wed, 10 Sep 2003 22:21:09 -0500 |

----- Original Message ----- From: "Jitian Sheu" <jtsheu@bu.edu> To: <statalist@hsphsun2.harvard.edu> Sent: Wednesday, September 10, 2003 10:01 AM Subject: st: Creating variables = sum(last year) > Dear Listers: > I am not sure my subject title is correct > > My question is as following: > > Suppose I have data as following: > > obs id date vol X > 1 1 01 jan 1995 a - > 2 1 28 feb 1995 b a > 3 1 31 oct 1996 c a > 4 1 25 dec 1996 d d > 5 1 29 dec 1996 e c+d > 6 1 15 nov 1997 f c+d > 7 2 01 jan 1994 g - > 8 2 10 jan 1994 h g > 9 2 25 jan 1994 i g+h > 10 2 3 feb 1994 j g+h+i > 11 2 28 feb 1994 k g+h+i+j > 12 2 01 jan 1995 l g+h+i+j+k > 13 2 11 jan 1995 m g+h+i+j+k+l > > > What I want is a new varialbe, say call X > Where X is the summation of "VOL" for the same ID, but, the summation only > count for one year behind the date of underlying observation. > > For example, take a look for observation #5. > This observation has date ="29 Dec 1996" (for ID=1) > The value of this new variable = all "VOL" occured between "29 Dec 1995" - > "28 Dec 1996". > In this case the value is "c+d" > > Take another example. > Let's see the observation #10. > This observation has date= "3 Feb 1994" > I want the X to be the summation of all VOL occured between "3 Feb 1993" to > "2 Feb 1994", ===> =g+h+i > > > Does anyone have suggestion? > > > Thank you very much > > > JT > No suggestions, but a question about variable x. If x is the the sum of last year's vol then should not x = . for observation 3, since the time span from observation 2 to 3 is one year eight months; observation 6 would be the sum of observations 4 and 5 and obersvation 12 would be the sum of observations 9 - 11. So, should the final data set look something like this: obs id date vol X 1 1 01 jan 1995 a - 2 1 28 feb 1995 b a 3 1 31 oct 1996 c - 4 1 25 dec 1996 d c 5 1 29 dec 1996 e c+d 6 1 15 nov 1997 f d+e 7 2 01 jan 1994 g - 8 2 10 jan 1994 h g 9 2 25 jan 1994 i g+h 10 2 3 feb 1994 j g+h+i 11 2 28 feb 1994 k g+h+i+j 12 2 01 jan 1995 l g+h+i+j+k 13 2 11 jan 1995 m i+j+k+l Scott * * 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/

**Follow-Ups**:**st: Re: Re: Creating variables = sum(last year)***From:*"Jitian Sheu" <jtsheu@bu.edu>

**References**:**RE: st: Stata update***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**st: Creating variables = sum(last year)***From:*"Jitian Sheu" <jtsheu@bu.edu>

- Prev by Date:
**Re: st: Survey Data** - Next by Date:
**st: Re: Re: Creating variables = sum(last year)** - Previous by thread:
**st: RE: Creating variables = sum(last year)** - Next by thread:
**st: Re: Re: Creating variables = sum(last year)** - Index(es):

© Copyright 1996–2016 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |