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: Forvalues to make a moving average on non timeseries data.
From
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: Forvalues to make a moving average on non timeseries data.
Date
Mon, 17 Mar 2014 16:34:10 +0000
The FAQ does have advice on homework, so you are bitten by Catch-22 or
perhaps 42.
Having declared this honestly as homework, you have placed this beyond
the scope of the list. Naturally, I don't have, and don't want, the
power to forbid or prevent anyone answering, but we do have a policy.
Nick
[email protected]
On 17 March 2014 15:49, Snapp, Kevin Michael <[email protected]> wrote:
> Hello Stata-nauts
>
> I have to make a disclosure, this is for a homework assignment. I've
> emailed the professor but I haven't had a response yet, as its spring
> break. We are working through the Cameron and Trivedi
> "Microeconometrics Using Stata." On pp 71 there is a problem I can't
> figure out, #6. I am asked to sort a selection of PSID data by hours
> worked (hours) then calculated a moving average of the log of earnings
> (lnearns) for a section of the data. The book suggests using
> forvalues, but I can't figure it out for the life of me. I've
> searched the statalist and found something similar but still no luck.
>
> Here is my first attempt:
>
> observations 2037 through 2053 are the ones I need a moving average
> for. My plan was to get the sum of the 25 observations and then dived
> by 25 in a separate step.
>
> generate MA = .
> forvalues i = 2037/2053 {
> forvalues j -12/12 {
> quietly replace MA[`i'] =( MA[`i'] + lnearns[`j' + `i'])
> }
> }
>
> The error message I get says weights not allowed
>
> I have tried it without nesting:
>
> generate MA = .
> forvalues j -12/12 {
> quietly replace MA = MA + lnearns[`j']
> }
>
> and it runs, but it doesn't change any values (afterwards there are 0
> observations of MA).
>
> Any advice is appreciated
>
> Regards
> Kevin Snapp
> IUPUI Economics
> [email protected]
>
>
> *
> * 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/
*
* 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/