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: scaling by average
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: scaling by average
Date
Wed, 12 Dec 2012 09:51:29 +0000
The -sum()- here looks wrong as the function returns cumulative sums
and your additions are explicit any way. If I understand you correctly
you want
tsset state date
gen average = (score* count + L7.score*L7.count + F7.score*F7.count) /
(count + L7.count + F7.count)
but if this is weekly data, then
tsset state date, delta(7)
gen average = (score* count + L1.score*L1.count + F1.score*F1.count) /
(count + L1.count + F1.count)
is simpler.
Nick
On Tue, Dec 11, 2012 at 9:10 PM, Claudius Li
<[email protected]> wrote:
> I've got an other question on the panel data set from my previous post.
> I've reshaped it so that I now have
>
> date state score time <other stuff>
>
> I want to add a variable normalized_score = score - average_for_day
> Where average_for_day = sum(score * count + score[n-7] * count[n-7]
> +score[n+7] * count[n+7] ... ) / sum(count + count[n-7] + count[n+7]
> ... )
>
> It seems a bit complicated to do this with loops. Is there a simpler way?
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/