Statalist The Stata Listserver


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

Re: st: weighted cumulative sum


From   "Austin Nichols" <[email protected]>
To   [email protected]
Subject   Re: st: weighted cumulative sum
Date   Wed, 1 Mar 2006 01:24:53 -0500

bys id (year): gen exper1=pr[_n-3]/3+pr[_n-2]/2+pr[_n-1]

and you could extend this to more periods (say n>3),
but you will have exper1 missing for the first n periods
within each panel defined by id.

see also -tsset- and [U] 11.4.3 Time-series varlists

On 2/28/06, Arik <[email protected]> wrote:
> Hello,
>
> I have a panel data of firms and the number of units
> of products they sell each year. I am trying to
> generate some measures of production experience.
>
> One measure I have simply produces a cumulative sum of
> the number of products sold up to the previous year:
> by id: gen experience1=sum(products[_n-1])
>
> I am now trying to produce more sophisticated measures
> that will discount the experience by some given rate
> (by, say, dividing the experience by its age). The
> idea is that last year's experience is more valuable
> than the experience of the year before it and so on.
>
> For example, if I have the following dataset
>
> year 1 - 30 products
> year 2 - 20 products
> year 3 - 10 products
> year 4 - 10 products
> year 5 - 20 products
>
> Right now, my experience measure for year 4 is
> 30+20+10=60. I am looking for a command that will give
> me the following value: (30/3)+(20/2)+(10/1)=30
>
> Any idea how can this be done?
>
> Cheers,
>
> Arik Lifschitz

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