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

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


From   "Jitian Sheu" <jtsheu@bu.edu>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Re: Re: Creating variables = sum(last year)
Date   Wed, 10 Sep 2003 23:36:13 -0400

you are right, sorry for my mistakes
----- Original Message ----- 
From: "Scott Merryman" <smerryman@kc.rr.com>
To: <statalist@hsphsun2.harvard.edu>
Sent: Wednesday, September 10, 2003 11:21 PM
Subject: st: Re: Creating variables = sum(last year)


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

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