Bookmark and Share

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]

st: Forvalues to make a moving average on non timeseries data.


From   "Snapp, Kevin Michael" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: Forvalues to make a moving average on non timeseries data.
Date   Mon, 17 Mar 2014 15:49:51 +0000

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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index