Wednesday, March 01, 2006
RE: st: weighted cumulative sum
-egen, filter()- from -egenmore- on SSC.
Austin Nichols > 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 Arik <email@example.com> wrote:
> > 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
* * 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/
Links to this post: