Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: scaling by average


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
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
<claudiusli@janysanalytics.com> 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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index