Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Weighted average of historical observations
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: Weighted average of historical observations
Date
Fri, 27 Jan 2012 09:21:11 +0000
You could use -egen, total()- to get the individual sums, using -by:-
or -by()- to do the calculation separately for individuals. Then
divide. Nothing outside Stata required.
Nick
On Fri, Jan 27, 2012 at 4:52 AM, Samuel Yeo <[email protected]> wrote:
> I have annual data on a variable, X, for a set of individuals. Given
> their ages, I would like to generate a new variable X_HIS, which is a
> weighted average of their past experiences of X through their
> lifetimes. X_HIS would therefore incorporate all observations of X,
> over each individual's lifetime.
>
> The calculation for X_HIS would be:
>
> WEIGHT FOR A GIVEN YEAR = (AGE - k)^m
> where k is the time lag (in years), increasing from 1 to each
> individual's AGE; m is an arbitrary parameter
>
> X_HIS = SUM(WEIGHT FOR A GIVEN YEAR * X) / (SUM OF WEIGHT FOR ALL YEARS)
>
> Is there a way to do this in Stata, or would I need to do it elsewhere
> and import it in?
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/